Summary

Application level configuration.

Original Author

Christopher J. Bottaro

Merb Port

Jacques Crocker

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_entr

Common config file

Config entries defined in

Merb.root/config/app_config/settings.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:

Merb.root/config/app_config/development.yml

Example production environment config file:

Merb.root/config/app_config/production.yml

Embedded Ruby (ERB)

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

Easy Stylesheets and Javascripts

You can also define your javascripts and stylesheets using AppConfig

Merb.root/config/javascripts.yml Merb.root/config/stylesheets.yml

  • prototype-bundle:

    • prototype

    • scriptaculous

  • jquery-bundle:

    • jquery

    • jquery.ui/tabs

  • components-bundle:

    • components/blah

    • components/blah2

This will include all the javasciprt files listed when running the helper “javascripts”, and on prod, it will bundle them up by key (prototype-bundle.js, jquery-bundle.js, components-bundle.js)

If you want to see something really awesome, try this:

  • jquery-bundle:

    • jquery

    • jquery.ui/*

    • jquery.plugins/*

On the first request this will grab ALL the files from these folders (using Dir), and bundle them on. On subsequent requests, it will use the bundle directly

In your application layout, just include the calls to <%= stylesheets %> <%= javascripts %>

Examples

Consider the two following config files.

Merb.root/config/app_config.yml:

size: 1
server: google.com

Merb.root/config/app_config/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