Module: ButlerMainframe::Settings

Extended by:
Settings
Included in:
Settings
Defined in:
lib/core/configuration_dynamic.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



61
62
63
64
# File 'lib/core/configuration_dynamic.rb', line 61

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.



38
39
40
# File 'lib/core/configuration_dynamic.rb', line 38

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



55
56
57
58
59
# File 'lib/core/configuration_dynamic.rb', line 55

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

This is the main point of entry - we call Settings.load! and provide a name of the file to read as it’s argument. We can also pass in some options, but at the moment it’s being used to allow per-environment overrides in Rails



44
45
46
47
48
49
50
51
# File 'lib/core/configuration_dynamic.rb', line 44

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