Loadcfg is a project mainly written in Ruby, it's free.
Load environment configuration as constants just knowing the YAML file name.
== loadcfg
Rails gem for read environment variables configuration, just follow some convention.
== Install
gem install loadcfg
or then add gem 'loadcfg' to your Gemfile and run:
bundle install
== Usage
Let's say you have some configuration variables that depend of the environment you are working on, for example config/facebook.yml
development:
app_id:
One of the conventions is that you should put the file in the config directory of your rails project, then, in any class where you want to use the constants you just need to call loadconfig method passing the config file name as a symbol, for example:
class FacebookHelper loadconfig :facebook end
that's going to generate a constant for each key in the yaml config file, each constant will has file name as a prefix, for example:
class FacebookHelper loadconfig :facebook
def some_method_that_deals_with_facebook_api
fb_id = FACEBOOK_APP_ID
fb_secret_key = FACEBOOK_SECRET_KEY
# here fb_id and fb_secret_key contain the values you gave them for the environment you are working on
end
end
== Options
There is a couple of options you can pass to loadconfig method
loadconfig :facebook, :environment => :my_environment, :ignore_not_found => true
If there's no my_environment entry in the config/facebook.yml file there will be no exception raised.
That's it.