Class: R10K::Deployment::Config Private

Inherits:
Object
  • Object
show all
Defined in:
lib/r10k/deployment/config.rb,
lib/r10k/deployment/config/loader.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: ConfigError, Loader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configfile) ⇒ Config

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Config.



11
12
13
14
15
# File 'lib/r10k/deployment/config.rb', line 11

def initialize(configfile)
  @configfile = configfile

  load_config
end

Instance Attribute Details

#configfileObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/r10k/deployment/config.rb', line 9

def configfile
  @configfile
end

Instance Method Details

#load_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Load and store a config file, and set relevant options

Parameters:

  • configfile (String)

    The path to the YAML config file



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/r10k/deployment/config.rb', line 37

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.message}"
  end
end

#setting(key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Perform a scan for key and check for both string and symbol keys



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/r10k/deployment/config.rb', line 18

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