Class: Splunk::Pickaxe::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/splunk/pickaxe/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, execution_path) ⇒ Config

Returns a new instance of Config.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/splunk/pickaxe/config.rb', line 29

def initialize(config, execution_path)
  unless config['namespace'].key? 'app'
    raise "Config must have a 'namespace / app' config"
  end

  raise "Must have at least one environment" unless config['environments'].size > 0

  @config = config
  @execution_path = execution_path

  @environments = config['environments']

  # Convert namespace config hash to hash with symbols for keys
  namespace_config = config['namespace'].each_with_object({}) { |(k, v), memo| memo[k.to_sym] = v; }
  @namespace = Splunk.namespace(namespace_config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



27
28
29
# File 'lib/splunk/pickaxe/config.rb', line 27

def config
  @config
end

#environmentsObject (readonly)

Returns the value of attribute environments.



27
28
29
# File 'lib/splunk/pickaxe/config.rb', line 27

def environments
  @environments
end

#execution_pathObject (readonly)

Returns the value of attribute execution_path.



27
28
29
# File 'lib/splunk/pickaxe/config.rb', line 27

def execution_path
  @execution_path
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



27
28
29
# File 'lib/splunk/pickaxe/config.rb', line 27

def namespace
  @namespace
end

Class Method Details

.load(execution_path) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/splunk/pickaxe/config.rb', line 19

def self.load(execution_path)
  config_path = File.join(execution_path, CONFIG_FILE)
  raise "Unable to load config file [#{config_path}]" unless File.exist? config_path

  # Merges DEFAULTS with yaml config
  Config.new deep_merge(DEFAULTS, YAML.load_file(config_path)), execution_path
end