Generates a configuration object:
-
Pass in a YAML file
-
Pass in an environment as a filter
-
Use YAML defaults
-
Use ERB
-
Returns an OpenStruct so top level attributes can be accessed via method
Here is how a configuration file could look like:
application: RailsConfig version: <%= 'version'.upcase %> defaults: &defaults payment: key: payment_key development: <<: *defaults payment: key: development_payment_key production: <<: *defaults
gem install phuesler-simple_app_config
Via gem cutter (www.gemcutter.org)¶ ↑
gem install gemcutter gem tumble gem install simple_app_config
require 'simple_app_config' Config = AppConfig.create("config/application.yml", :environment => 'development') puts Config.application puts Config.payment['key']
Or if you prefer the hash syntax do
require 'simple_app_config' Config = AppConfig.create("config/application.yml", :environment => 'development', :format => :hash) puts Config.application puts Config['payment']['key']
When used in a Rails project, create an initializer and add something like this:
require 'simple_app_config' Config = AppConfig.create("#{Rails.root}/config/application.yml", :environment => Rails.env)
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but
bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright © 2009 Patrick Huesler. See LICENSE for details.