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({:some_key => ‘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

Contributors

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