Friday, March 16, 2007

[PLUGIN RELEASE] Configuration Files Loader v1.0.0

Configuration Files Loader can be used as a gem or a Rails plugin to load various config files.

It finds config file fragments in a Rails config directory and in config directories of plugins and dependent gems. It then tries to merge them in the following order: gem<-plugin<-application. This allows overrides of global (gem/plugin) configs by individual applications. The supported types for merging are String, Hash, and Array. It caches the content of files by default. ConfigurationLoader is RoR environment aware and provides a shortcut (load_section) to load a section of a config file corresponding to RAILS_ENV. It is being used in another method provided by ConfigurationLoader - load_db_config. It loads a section from config/database.yml providing a convenient method for placing secondary DB entries in a code as seen here:

establish_connection ConfigurationLoader.load_db_config['secondary_db']

See the DRYing Up Configuration Files post in our team blog for additional details.


Setup

Installation

To install Configuration Files Loader as a gem:

Use gem install configuration_loader or download the gem file from the project page and install it.

To install it as a Rails plugin:

ruby script/plugin install svn://rubyforge.org/var/svn/config-loader/trunk/vendor/plugins/configuration_loader


Usage

require 'configuration_loader'

ConfigurationLoader.load_db_config # gets the RAILS_ENV section from database.yml

ConfigurationLoader.load('cfg.yml') # loads a YAML-processed config file

ConfigurationLoader.load('cfg.yml', :erb => true) # loads a ERB+YAML-processed config file

ConfigurationLoader.load('cfg.yml', :section => RAILS_ENV) # loads a current RAILS_ENV section from a YAML-processed config file

ConfigLoader.load('cfg.yml', :cache => false) # loads an uncached copy of a YAML-processed config file


License

Configuration Files Loader is released under the MIT license.

Update by Sean (6/20/2008)
This is now available on github as a gem.

To install:
gem install revolutionhealth-config_loader -s http://gems.github.com

Or simply add the following to your Rails 2.1-compatible application:
config.gem 'revolutionhealth-config_loader', :lib => 'config_loader', :source => 'http://gems.github.com'