public
Description: Rails plugin that provides environment specific application configuration.
Homepage: http://blog.stochasticbytes.com/2007/10/better-appconfig-plugin-for-rails.html
Clone URL: git://github.com/cjbottaro/app_config.git
name age message
file CHANGELOG Fri Oct 03 14:57:11 -0700 2008 config files are now recursively merged [cjbottaro]
file README Mon May 19 10:21:21 -0700 2008 moving to git from svn [Christopher J. Bottaro]
file README.rdoc Fri Oct 03 14:57:11 -0700 2008 config files are now recursively merged [cjbottaro]
file Rakefile Mon May 19 10:21:21 -0700 2008 moving to git from svn [Christopher J. Bottaro]
file init.rb Mon May 19 10:21:21 -0700 2008 moving to git from svn [Christopher J. Bottaro]
file install.rb Mon May 19 10:21:21 -0700 2008 moving to git from svn [Christopher J. Bottaro]
directory lib/ Fri Oct 03 14:57:11 -0700 2008 config files are now recursively merged [cjbottaro]
directory tasks/ Mon May 19 10:21:21 -0700 2008 moving to git from svn [Christopher J. Bottaro]
directory test/ Fri Oct 03 14:57:11 -0700 2008 config files are now recursively merged [cjbottaro]
file uninstall.rb Mon May 19 10:21:21 -0700 2008 moving to git from svn [Christopher J. Bottaro]
README.rdoc

Summary

Application level configuration.

Author

Christopher J. Bottaro

Accessing the AppConfig object

After installing this plugin, the AppConfig object will be global available. Entries are accessed via object member notation:

 AppConfig.my_config_entry

Nested entries are supported:

 AppConfig.my_section.some_entry

Common config file

Config entries defined in

 RAILS_ROOT/config/app_config.yml

will be available to all environments.

Environment specific config files

You can have environment specific config files. Environment specific config entries take precedence over common config entries.

Example development environment config file:

 RAILS_ROOT/config/environments/development.yml

Example production environment config file:

 RAILS_ROOT/config/environments/production.yml

UPDATE (10/03/2008)

The config files are recursively merged now. Thus the following works:

RAILS_ROOT/config/app_config.yml:

  servers:
    dev:  dev.domain.com
    test: test.domain.com

RAILS_ROOT/config/environments/production.yml:

  servers:
    test: testing.domain.com
    prod: prod.domain.com

(application code):

  AppConfig.servers.dev  # => dev.domain.com
  AppConfig.servers.test # => testing.domain.com
  AppConfig.servers.prod # => prod.domain.com

Whereas before, the "servers" section of production.yml would completely overwrite the "servers" section of app_config.yml and you would get:

  AppConfig.servers.dev  # => nil
  AppConfig.servers.test # => testing.domain.com
  AppConfig.servers.prod # => prod.domain.com

Embedded Ruby (ERB)

 Embedded Ruby is allowed in the configuration files.  See examples below.

Examples

Consider the two following config files.

RAILS_ROOT/config/app_config.yml:

 size: 1
 server: google.com

RAILS_ROOT/config/environments/development.yml:

 size: 2
 computed: <%= 1 + 2 + 3 %>
 section:
   size: 3
   servers: [ {name: yahoo.com}, {name: amazon.com} ]

Notice that the environment specific config entries overwrite the common entries.

 AppConfig.size -> 2
 AppConfig.server -> google.com

Notice the embedded Ruby.

 AppConfig.computed -> 6

Notice that object member notation is maintained even in nested entries.

 AppConfig.section.size -> 3

Notice array notation and object member notation is maintained.

 AppConfig.section.servers[0].name -> yahoo.com
 AppConfig.section.servers[1].name -> amazon.com