AppConfig Plugin for Rails

Its probably because I come from the Java world that I felt compelled to create an app configuration mechanism which enabled easy externalization of app properties.  This is not an Earth-shattering, whiz-bang plugin, so I’m not going to oversell it.  Quite simply, this plugin just enables you to put properties into an app.yml file and manage it nicely with Capistrano.  So maybe this’ll save you 10 minutes of coding.  Here goes:

FEATURE SUMMARY

This plugin provides for easy externalized configurization in a YML file:

  • Common and environment-specific configuration contained in a single YML file.
  • Capistrano task to preserve configuration file from release to release.

USAGE
Place configuration elements common to all environments in the common area as demonstrated below:

1
2
3
# Configuration for ALL environments.
common: &common
  app_name: your_app_name_here

Place environment-specific elements under appropriate environment as shown below:

1
2
3
4
5
# Configuration for PRODUCTION environment.
production:
  <<: *common
  google_api: some_long_api_key_here

To obtain the values from anywhere in your code, simply access the attributes of the environment like so:

1
2
3
puts AppConfig.app_name
puts AppConfig.google_api

DEPLOYMENT

To preserve the configuration values across releases, call the symlink_app_config task from within the after_update_code task.

1
2
3
task :after_update_code, :roles => :app do
  symlink_app_config
end

To update the app.yml file for the first time or for subsequent times, the task update_app_config can be used as below:

cap update_app_config

This takes the app.yml file from the config directory of the application and uploads it to the release path on the server.

You can get it here:

script/plugin install http://dev.billeisenhauer.com/svn/projects/plugins/appconfig

Hope someone finds this useful.

This entry was posted in Ruby, Ruby on Rails. Bookmark the permalink.

One Response to AppConfig Plugin for Rails

  1. Yahoouj says:

    Really good work about this website was done. Keep trying more – thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>