Class: Splunk::Pickaxe::Config
- Inherits:
-
Object
- Object
- Splunk::Pickaxe::Config
- Defined in:
- lib/splunk/pickaxe/config.rb
Instance Attribute Summary collapse
-
#emails ⇒ Object
readonly
Returns the value of attribute emails.
-
#env_config ⇒ Object
readonly
Returns the value of attribute env_config.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#execution_path ⇒ Object
readonly
Returns the value of attribute execution_path.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config, environment, execution_path) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(config, environment, 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 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/splunk/pickaxe/config.rb', line 29 def initialize(config, environment, execution_path) raise "Config must have a 'namespace / app' config" unless config['namespace'].key?('app') raise "Environment [#{environment}] is not configured" unless config['environments'].has_key?(environment) @execution_path = execution_path @environment = environment env_config = config['environments'][environment] if env_config.is_a?(String) # Support this for now to be passive but we will remove it later puts "Your .pickaxe.yml is using a deprecated config format. Check https://github.com/cerner/splunk-pickaxe#backwards-compatibility for details" @emails = config['emails'] @url = env_config @env_config = { 'url' => @url, 'emails' => @emails } elsif env_config.is_a?(Hash) raise "url config is required for environment [#{environment}]" unless env_config.has_key?('url') @url = env_config['url'] @emails = env_config.has_key?('emails') ? env_config['emails'] : config['emails'] @env_config = env_config else raise "Unexepcted value for environment [#{environment}] config. Expected String or Hash, saw #{config['environments'][environment]}" end # 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
#emails ⇒ Object (readonly)
Returns the value of attribute emails.
27 28 29 |
# File 'lib/splunk/pickaxe/config.rb', line 27 def emails @emails end |
#env_config ⇒ Object (readonly)
Returns the value of attribute env_config.
27 28 29 |
# File 'lib/splunk/pickaxe/config.rb', line 27 def env_config @env_config end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
27 28 29 |
# File 'lib/splunk/pickaxe/config.rb', line 27 def environment @environment end |
#execution_path ⇒ Object (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 |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
27 28 29 |
# File 'lib/splunk/pickaxe/config.rb', line 27 def namespace @namespace end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
27 28 29 |
# File 'lib/splunk/pickaxe/config.rb', line 27 def url @url end |
Class Method Details
.load(environment, execution_path) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/splunk/pickaxe/config.rb', line 19 def self.load(environment, 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)), environment, execution_path end |