Configulations - You can have a simple configuration class for Ruby apps!

This is a bare bones, simple way to add configuration files to your ruby apps using either json or yml. Then, you can simply call into the configurator like any plain ol’ Ruby object using the message passing dot syntax rather than hash/ordinal accessors.

Included is a module called MagicHash that does all the magic mapping for the object. It should be considered pretty dangerous as it augments the expected behavior of Hash. To ensure as much flexibility without damaging Hash directly, configurator simply extends the instance of the property bag so that we get the power of hash without messing up hash for any one that is using it.

EXAMPLE

by default, Configulations is going to recursively dive into a “config” directory located by the location of the executing ruby process. from there, any files ending in .yml or .json with the respetive content-types of YAML or JSON will be loaded. The name of the file is the first key and all properties can be fetched from there.

config = Configulations.new #=> finds config/server.json and config/admins.yml
config.server.host #=> "localhost"
config.admins.include? User.find_by_name("leon") #=> true

Thanks to tonywok for starting the inheritance work… this is now possible:

structure:

config/
--application.yml   #=> (host: 'production.local')
--application/
-----development.yml #=> (host: 'development.local')
-----test.yml        #=> (host: 'test.local')

if each has a host… then you can call it like so…

ENV["APP_ENV"] ||= "test" #=> current support vars are "RACK_ENV", "RAILS_ENV", "APP_ENV"
MyConfig.application.host.should == "test.local"

Known Issues

Future

This is all I needed for now but I’d love to work out those issues mentioned above as well as allow for some robust Ruby configuration files that could take advantage of run time-evaluation and flow control for those situations when you’d like to let configuration be a bit more flexible than a yml, json file would allow.

Contributing to configulations

Contributors

Many thanks to anyone who sends patches, emails, love my way to keep this software alive and a joy to maintain.

Copyright © 2011 Leon Gersing. See LICENSE.txt for further details.