This is some sample code with no dependencies.
I've later extracted this into a separate library called choices.
| # needs the "hashie" gem in Gemfile | |
| require 'erb' | |
| module Movies | |
| class Application < Rails::Application | |
| # read from "settings.yml" and optional "settings.local.yml" | |
| settings = ERB.new(IO.read(File.expand_path('../settings.yml', __FILE__))).result | |
| mash = Hashie::Mash.new(YAML::load(settings)[Rails.env.to_s]) | |
| optional_file = File.expand_path('../settings.local.yml', __FILE__) | |
| if File.exists? optional_file | |
| optional_settings = ERB.new(IO.read(optional_file)).result | |
| optional_values = YAML::load(optional_settings)[Rails.env.to_s] | |
| mash.update optional_values if optional_values | |
| end | |
| mash.each do |key, value| | |
| config.send("#{key}=", value) | |
| end | |
| # now we can use those settings happily | |
| initializer "MongoMapper connect" do | |
| MongoMapper.config = { Rails.env => config.mongodb } | |
| MongoMapper.connect(Rails.env) | |
| end | |
| config.middleware.use Twitter::Login, | |
| :consumer_key => config.twitter.consumer_key, :secret => config.twitter.secret | |
| config.facebook_client = Facebook::Client.new(config.facebook.app_id, config.facebook.secret, | |
| :user_fields => %w[link name email website timezone movies]) | |
| end | |
| end |
See https://github.com/mislav/choices