Module: AutoHeathen::Config

Included in:
EmailProcessor
Defined in:
lib/autoheathen/config.rb

Instance Method Summary collapse

Instance Method Details

#load_config(defaults = {}, config_file = nil, overwrites = {}) ⇒ Object


3
4
5
6
7
8
9
10
# File 'lib/autoheathen/config.rb', line 3

def load_config defaults={}, config_file=nil, overwrites={}
  cfg = symbolize_keys(defaults)
  if config_file && File.exist?(config_file)
    cfg.merge! symbolize_keys(YAML::load_file config_file)
  end
  cfg.merge! symbolize_keys(overwrites)  # non-file opts have precedence
  return cfg
end

#symbolize_keys(hash) ⇒ Object


12
13
14
15
16
17
18
19
# File 'lib/autoheathen/config.rb', line 12

def symbolize_keys(hash)
  (hash||{}).inject({}){|result, (key, value)|
    new_key = key.is_a?(String) ? key.to_sym : key
    new_value = value.is_a?(Hash) ? symbolize_keys(value) : value
    result[new_key] = new_value
    result
  }
end