Module: Dorothy::DoroSettings

Extended by:
DoroSettings
Included in:
DoroSettings
Defined in:
lib/dorothy2/Settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



29
30
31
32
# File 'lib/dorothy2/Settings.rb', line 29

def method_missing(name, *args, &block)
  @_settings[name.to_sym] ||
      fail(NoMethodError, "unknown configuration root #{name}", caller)
end

Instance Attribute Details

#_settingsObject (readonly)

Returns the value of attribute _settings.



10
11
12
# File 'lib/dorothy2/Settings.rb', line 10

def _settings
  @_settings
end

Instance Method Details

#deep_merge!(target, data) ⇒ Object

Deep merging of hashes deep_merge by Stefan Rusterholz, see www.ruby-forum.com/topic/142809



23
24
25
26
27
# File 'lib/dorothy2/Settings.rb', line 23

def deep_merge!(target, data)
  merger = proc{|key, v1, v2|
    Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
  target.merge! data, &merger
end

#load!(filename, options = {}) ⇒ Object



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

def load!(filename, options = {})
  t  = YAML::load_file(filename).extend DeepSymbolizable
  newsets = t.deep_symbolize
  newsets = newsets[options[:env].to_sym] if \
                                           options[:env] && \
                                           newsets[options[:env].to_sym]
  deep_merge!(@_settings, newsets)
end