Clean your configuration with configuration_manager

If you’re spreading constants around your environments files to configure your Rails apps based on the environment it is running on, stop immediately! Let’s say it’s not very wise… ;)
There’s no point in having lots of different constants all around your code that basically all do the same thing: configure your app.

Instead, you should do something similar to what Geoffrey Grosenbach suggests in Rails Code Review — BTW, we translated that PDF in Italian: have a YAML file in your config directory where you store all of the settings for your app grouped by environment.

I said you should do something similar, because what Geoffrey suggests is just a starting point and that solution can be made a tad more elegant.
Which is what our new plugin is about!

ConfigurationManager allows you to have a single YAML file where you can store all of your settings, then setup a single constant which can be used all over your app by doing something like ConstantName.setting_name; or even ConstantName.group_of_settings.setting_name.

The YAML file should be placed in config/configuration_manager.yml and it should contain your settings like this:

everyone: &every_env
  key1: value1
  inner_hash:
    key2: value2

development: &non_production_env
  <<: *every_env
  key3: value3

test:
  <<: *non_production_env

production:
  <<: *every_env
  key4: value4

Then in your environment.rb you put the following:

MyConfig = ConfigurationManager.new_manager

Which will allow you to access your settings wherever you need them:

MyConfig.inner_hash.key2 #=> value2
MyConfig.key4 #=> value4
etc...

I hope you get the idea…it should make sense. :)

Development of the plugin is on Github, but you can install it from our usual Google Code repository:

script/plugin install http://wonsys.googlecode.com/svn/plugins/configuration_manager/

If you find any bugs, please let us know using our bug tracker.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Reddit
  • Ma.gnolia
  • MisterWong
  • Furl
  • Netscape
  • NewsVine
  • Simpy
  • Spurl
  • StumbleUpon
  • Taggly
  • YahooMyWeb

This post was written by Michele 5 months, 3 weeks ago on May 29th, 2008 mid-afternoon.
Tags: , , , .

Comments feed Comments (None so far)

No Comments, yet! Be the first to leave one!

Post a comment

Comment moderation is enabled. If your comment is not visible immediately, please do not resubmit it.