-
Notifications
You must be signed in to change notification settings - Fork 1
Home
brendan edited this page Sep 12, 2010
·
16 revisions
SimpleConfig — Making config, er… simple!
I’ll start with an example. This may be all you need to grok.
# config/some_service.yml api: url: http://someservice/api/1 key: 123 enabled: false
# config/local/some_service.yml api: key: 456 enabled: true
# irb
>> CONFIG = SimpleConfig.new("config/local", "config") # <= as many paths as you want
=> {}
>> CONFIG.some_service.enabled
=> true
>> CONFIG.some_service.api.url
=> http://someservice/api/1
>> CONFIG.some_service.api.key
=> 456
How to install:
# command-line $ gem sources -a http://gems.github.com (you only have to do this once) $ sudo gem install brendan-simpleconfig
# your_code.rb require 'rubygems' require 'simpleconfig'
Other behavioral details/features worth noting:
- All yml files are preprocessed with ERb, so you can embed dynamic content in them ala `<%= 1 + 1 %>`
- You will still get a method_missing error if you try to access a key that doesn’t exist.
- Once data is loaded into the SimpleConfig hash, that key’s contents are recursively frozen, so you do not accidentally modify your configuration data at Runtime.