module Choices

Public Instance Methods

load_settings(filename, env) click to toggle source
# File lib/choices.rb, line 7
def load_settings(filename, env)
  mash = Hashie::Mash.new(load_settings_hash(filename, env))
  
  with_local_settings(filename, env, '.local') do |local|
    mash.update local
  end
  
  return mash
end
load_settings_hash(filename, env) click to toggle source
# File lib/choices.rb, line 17
def load_settings_hash(filename, env)
  yaml_content = ERB.new(IO.read(filename)).result
  YAML::load(yaml_content)[env]
end
with_local_settings(filename, env, suffix) { |hash| ... } click to toggle source
# File lib/choices.rb, line 22
def with_local_settings(filename, env, suffix)
  local_filename = filename.sub(/(\.\w+)?$/, "#{suffix}\\1")
  if File.exists? local_filename
    hash = load_settings_hash(local_filename, env)
    yield hash if hash
  end
end