appconfig

A gem for centralizing different sources of application configuration data. Supports YAML files, ActiveRecord models and simple hashes as data sources.

Usage

Adding configuration sources

From YAML file

AppCfg::Source.add(‘/path/to/configuration.yml’)

From namespaced YAML file

AppCfg::Source.add(‘/path/to/configuration.yml’, :env => Rails.env)

From ActiveRecord model

AppCfg::Source.add(ConfigurationModel)

From hash object

AppCfg::Source.add(=> ‘value’)

From .properties file (features missing! Refer to pending tests)

AppCfg::Source.add(‘/path/to/configuration.properties’)

Accessing configuration values

Configuration data can be accessed via both object and hash syntax, called on AppCfg module:

AppCfg.some_key # => 'value'
AppCfg['some_key'] # => 'value'

Note that these options differ when trying to access inexistent key:

AppCfg.wrong_key # => raises exception
AppCfg['wrong_key'] # => nil

Overwriting and reloading

Configuration sources are stacked in the order of being added:

AppCfg::Source.add({:some_key => 'some value'})
AppCfg::Source.add({:some_key => 'other value'})
AppCfg.some_key # => 'other value'

Configuration values are cached at the moment of being added. If sources are modified (for example, configuration values stored in database change), data can be refreshed via:

AppCfg::Source.reload_sources!

Contributing to appconfig

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Contributors

  • lorrin (Lorrin Nelson)

Copyright © 2011 Toms Mikoss. See LICENSE.txt for further details.