module Wms::Config::Mixin::MixinClassMethod

This inner module is defined for class method

Attributes

default[RW]

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/wms/config/mixin.rb, line 110
def deep_merge!(target, data)
  merger = proc{|key, v1, v2|
    Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
  target.merge! data, &merger
end
get_default(name) click to toggle source

return default value given name

# File lib/wms/config/mixin.rb, line 81
def get_default(name)
  key_name = if name.is_a?(Symbol) then name  else name.to_s end
  @default[key_name][:default] if @default[key_name]
end
set_default(name, opts) click to toggle source

Define a new configuration setting

# File lib/wms/config/mixin.rb, line 72
def set_default(name, opts)
  @default ||= Hash.new

  name = name.to_s unless name.is_a?(Symbol)
  @default[name] = opts  # ok if this is empty

end
source(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

Example Load without environment

> Settings.load!(“config/appdata/example.yml”)

Load with environment

> Settings.load!(

"#{Rails.root}/config/appdata/env-example.yml",
:env => Rails.env)
# File lib/wms/config/mixin.rb, line 99
def source(filename, options={})
  newsets = YAML::load_file(filename).deep_symbolize_keys
  newsets = newsets[options[:env].to_sym] if \
                                             options[:env] && \
                                             newsets[options[:env].to_sym]
  @default ||= Hash.new
  deep_merge!(@default, newsets)
end