Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

ConfigLoader makes it easy to load the values of a custom configuration file in a Rails project.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .bundle
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 configloader.gemspec
README.rdoc

configloader

If you need to create a custom config file for you Rails project, ConfigLoader will help you to load the contents of this file.

How to install the gem

gem install configloader

Usage

ConfigLoader.load(file_name, running_env, project_root)

Let's assume that you have the special file config/database.yml in your Rails project.
In this example, you are using CouchDB as your database. This file has the content below:

    development:
      server: localhost
      port: 5984
      database_name: addressbook_development

    test:
      server: localhost
      port: 5984
      database_name: addressbook_test

    production:
      server: production.server.com
      port: 5984
      database_name: addressbook_production

In order to access the database configuration for your current environment, you'd write, for instance:

    db_config = ConfigLoader.load('database')
    db_config['server']                     # localhost
    db_config['port']                       # 5984
    db_config['database_name']              # addressbook_development

We're assuming that your current environment is development.

You can get the configuration of a specific running environment writing this:

    db_config = ConfigLoader.load('database', 'production')
    db_config['server']                     # production.server.com
    db_config['port']                       # 5984
    db_config['database_name']              # addressbook_production

You can specify the project root too. If you don't, it will assume the project root is Rails.root.
To change it, write:

    db_config = ConfigLoader.load('database', 'production')
    db_config = ConfigLoader.load('database', 'test', '/home/user/my_special_project_root')

Dinamic keys are also accepted. They're parsed using ERB. So, you're free to write a config file like this:

  test:
    server: <%= `hostname` %>
    port: 5984
    database_name: addressbook_test

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add specs for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 Vinicius Teles. See LICENSE for details.

Something went wrong with that request. Please try again.