Methods
public class
public instance
Classes and Modules
Class Rudy::Config::AccountsClass Rudy::Config::Commands
Class Rudy::Config::Defaults
Class Rudy::Config::Error
Class Rudy::Config::Machines
Class Rudy::Config::Routines
Public class methods
# File lib/rudy/config.rb, line 106 106: def self.init_config_dir 107: 108: unless File.exists?(Rudy::CONFIG_DIR) 109: puts "Creating #{Rudy::CONFIG_DIR}" 110: Dir.mkdir(Rudy::CONFIG_DIR, 0700) 111: end 112: 113: unless File.exists?(Rudy::CONFIG_FILE) 114: puts "Creating #{Rudy::CONFIG_FILE}" 115: rudy_config = Rudy::Utils.without_indent %Q` 116: accounts { # Account Access Indentifiers 117: aws { # amazon web services 118: name "Rudy Default" 119: accountnum "" 120: accesskey "" 121: secretkey "" 122: pkey "~/path/2/pk-xxxx.pem" 123: cert "~/path/2/cert-xxxx.pem" 124: } 125: } 126: ` 127: Rudy::Utils.write_to_file(Rudy::CONFIG_FILE, rudy_config, 'w', 0600) 128: end 129: end
Public instance methods
# File lib/rudy/config.rb, line 14 14: def accounts?; self.respond_to?(:accounts) && !self[:accounts].nil?; end
# File lib/rudy/config.rb, line 17 17: def commands?; self.respond_to?(:commands) && !self[:commands].nil?; end
# File lib/rudy/config.rb, line 15 15: def defaults?; self.respond_to?(:defaults) && !self[:defaults].nil?; end
Looks for a loads configuration files from standard locations.
./.rudy/config ~/.rudy/config ~/.rudy/*.rb ./Rudyfile ./machines.rb, ./routines.rb, ./commands.rb ./config/rudy/*.rb ./.rudy/*.rb /etc/rudy/*.rb
When multuple files are found, the configuration is NOT OVERRIDDEN, it’s ADDED or APPENDED depending on context. This means you can split configuration across as many files as you please.
There are five sections: accounts, defaults, machines, commands and routines.
By convention, accounts go in ./.rudy/config or ~/.rudy/config machines, commands, routines, and defaults configuration go in ./Rudyfile or into separate files in ./.rudy or ./config/rudy (machines.rb, commands.rb, …)
If adhoc_path is supplied (e.g. rudy -C config/file/path routines), this method will look for ~/.rudy/config or ./.rudy/config but none of the other default file locations other than the supplied path. If it’s an Array, all paths will be loaded.
# File lib/rudy/config.rb, line 71 71: def look_and_load(adhoc_path=nil) 72: cwd = Dir.pwd 73: cwd_path = File.join(cwd, '.rudy', 'config') 74: 75: # Attempt to load the core configuration file first. 76: # The "core" config file can have any or all configuration 77: # but it should generally only contain the access identifiers 78: # and defaults. That's why we only load one of them. 79: core_config_paths = [cwd_path, Rudy::CONFIG_FILE] 80: core_config_paths.each do |path| 81: next unless path && File.exists?(path) 82: @paths << path 83: break 84: end 85: 86: if adhoc_path.nil? 87: # self.keys returns the current config types (machines, routines, etc...) 88: typelist = self.keys.collect { |g| "#{g}.rb" }.join(',') 89: 90: # Rudy then looks for the rest of the config in these locations 91: @paths += Dir.glob(File.join(Rudy.sysinfo.home, '.rudy', '*.rb')) || [] 92: @paths += Dir.glob(File.join(cwd, 'Rudyfile')) || [] 93: @paths += Dir.glob(File.join(cwd, 'config', 'rudy', '*.rb')) || [] 94: @paths += Dir.glob(File.join(cwd, '.rudy', '*.rb')) || [] 95: @paths += Dir.glob(File.join(cwd, "{#{typelist}}")) || [] 96: @paths += Dir.glob(File.join('/etc', 'rudy', '*.rb')) || [] 97: @paths &&= @paths.uniq 98: else 99: @paths += [adhoc_path].flatten 100: end 101: 102: refresh 103: end
# File lib/rudy/config.rb, line 16 16: def machines?; self.respond_to?(:machines) && !self[:machines].nil?; end
This method is called by Caesars::Config.refresh for every DSL file that is loaded and parsed. If we want to run processing for a particular config (machines, @routines, etc...) we can do it here. Just wait until the instance variable is not nil.
# File lib/rudy/config.rb, line 24 24: def postprocess 25: #raise "There is no AWS info configured" if self.accounts.nil? 26: 27: # These don't work anymore. Caesars bug? 28: #if accounts? && !self.accounts.aws.nil? 29: # self.accounts.aws.cert &&= File.expand_path(self.accounts.aws.cert) 30: # self.accounts.aws.privatekey &&= File.expand_path(self.accounts.aws.privatekey) 31: #end 32: 33: # The commands config modifies the way the routines configs 34: # should be parsed. This happens in the postprocess method 35: # we call here. We can't guarantee this will run before the 36: # routines config is loaded so this postprocess method will 37: # raise a Caesars::Config::ForceRefresh exception if that's 38: # the case. Rudy::Config::Commands knows to only raise the 39: # exception one time (using a boolean flag in a class var). 40: @commands.postprocess if @commands 41: @defaults.postprocess if @defaults 42: 43: # default will be nil if non was specified. We at least want the object. 44: @defaults = Rudy::Config::Defaults.new if @defaults.nil? 45: end
# File lib/rudy/config.rb, line 18 18: def routines?; self.respond_to?(:routines) && !self[:routines].nil?; end