module LoraRb::Settings

Attributes

_settings[R]

Public Instance Methods

deep_merge!(target, data) click to toggle source

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

# File lib/core/configuration_dynamic.rb, line 62
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 = {}) click to toggle source

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

# File lib/core/configuration_dynamic.rb, line 44
def load!(filename, options = {})

  newsets =
    if defined?(ERB)
      YAML.load(ERB.new(File.read(filename)).result)
    else
      YAML::load_file(filename)
    end

  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
method_missing(name, *args, &block) click to toggle source
# File lib/core/configuration_dynamic.rb, line 68
def method_missing(name, *args, &block)
  @_settings[name.to_sym] ||
      fail(NoMethodError, "unknown configuration root #{name}", caller)
end