Class: R10K::Deployment::Config
- Inherits:
-
Object
- Object
- R10K::Deployment::Config
- Defined in:
- lib/r10k/deployment/config.rb,
lib/r10k/deployment/config/loader.rb
Defined Under Namespace
Classes: ConfigError, Loader
Instance Attribute Summary collapse
-
#configfile ⇒ Object
Returns the value of attribute configfile.
Instance Method Summary collapse
-
#initialize(configfile) ⇒ Config
constructor
A new instance of Config.
-
#load_config ⇒ Object
Load and store a config file, and set relevant options.
-
#setting(key) ⇒ Object
Perform a scan for key and check for both string and symbol keys.
Constructor Details
#initialize(configfile) ⇒ Config
Returns a new instance of Config.
10 11 12 13 14 |
# File 'lib/r10k/deployment/config.rb', line 10 def initialize(configfile) @configfile = configfile load_config end |
Instance Attribute Details
#configfile ⇒ Object
Returns the value of attribute configfile.
8 9 10 |
# File 'lib/r10k/deployment/config.rb', line 8 def configfile @configfile end |
Instance Method Details
#load_config ⇒ Object
Load and store a config file, and set relevant options
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/r10k/deployment/config.rb', line 36 def load_config if @configfile.nil? loader = R10K::Deployment::Config::Loader.new @configfile = loader.search if @configfile.nil? raise ConfigError, "No configuration file given, no config file found in parent directory, and no global config present" end end begin @config = YAML.load_file(@configfile) apply_config_settings rescue => e raise ConfigError, "Couldn't load config file: #{e.}" end end |
#setting(key) ⇒ Object
Perform a scan for key and check for both string and symbol keys
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/r10k/deployment/config.rb', line 17 def setting(key) keys = [key] case key when String keys << key.to_sym when Symbol keys << key.to_s end # Scan all possible keys to see if the config has a matching value keys.inject(nil) do |rv, k| v = @config[k] break v unless v.nil? end end |