module Choices
Public Instance Methods
load_settings(filename, env)
click to toggle source
# File lib/choices.rb, line 8 def load_settings(filename, env) mash = Hashie::Mash.new(load_settings_hash(filename)) with_local_settings(filename, '.local') do |local| mash.update local end mash.fetch(env) do raise IndexError, %{Missing key for "#{env}" in `#{filename}'} end end
load_settings_hash(filename)
click to toggle source
# File lib/choices.rb, line 20 def load_settings_hash(filename) yaml_content = ERB.new(IO.read(filename)).result yaml_load(yaml_content) end
with_local_settings(filename, suffix) { |hash| ... }
click to toggle source
# File lib/choices.rb, line 25 def with_local_settings(filename, suffix) local_filename = filename.sub(/(\.\w+)?$/, "#{suffix}\\1") if File.exists? local_filename hash = load_settings_hash(local_filename) yield hash if hash end end
yaml_load(content)
click to toggle source
# File lib/choices.rb, line 33 def yaml_load(content) if defined?(YAML::ENGINE) && defined?(Syck) # avoid using broken Psych in 1.9.2 old_yamler = YAML::ENGINE.yamler YAML::ENGINE.yamler = 'syck' end begin YAML::load(content) ensure YAML::ENGINE.yamler = old_yamler if defined?(YAML::ENGINE) && defined?(Syck) end end