Skip to content

amberbit/amberbit-config

Repository files navigation

AmberBit Config

Provides simple global configuration for ruby applications using YAML files.

Installation:

With bundler:


1. Edit Gemfile, located in your application and add the following line:
    gem 'amberbit-config'
2. Run bundle:
    bundle install
3. Use rake to generate configuration files:
    rake amberbit:config:setup
4. Make sure that ./config/app_config.yml stays in .gitignore

As a rails engine:


It will work without any other actions as a rails engine. It takes environment name from:

ENV['RAILS_ENV'] or ENV['RACK_ENV'] or ENV['APP_CONFIG_ENV']

AppConfig should be initialized before environment configuration. If you need to use it within ./config/application.rb then add after Bundler.require

require 'amberbit-config'
AmberbitConfig.initialize_within File.dirname(__FILE__)

Any ruby application


For any other app require and initialize AppConfig as above, just make sure that there’s an ENV variable. You can also specify files to load, i.e.:

require 'amberbit-config'
ENV['RACK_ENV'] = 'development'
AmberbitConfig.initialize 'config/app_config_default.yml', 'config/app_config.yml'

Tested with Ruby on Rails, Sinatra, and plain old ruby.

Usage:

Place your application configuration default values into ./config/app_config_default.yml:

default:
  application:
    name: SuperApp
    url: http://localhost:3000/

test:
  # overwrite application.url key only in test env
  application:
    url: http://testhost:3000/

And overwrite values you wish on per-installation basis in ./config/app_config.yml:

default:
  application:
    name: SuperApp specially for you

production:
  application:
    url: http://yoursuperhiperdomain.com

In your application Ruby code you can access the values in 2 following ways:

AppConfig["application"]["name"] #=> SuperApp specially for you

or

AppConfig.application.name #=> SuperApp specially for you

Keys are deep-merged, for example:

production env:

AppConfig.application.name #=> SuperApp specially for you
AppConfig.application.url #=> http://yoursuperhiperdomain.com

development env:

AppConfig.application.name #=> SuperApp specially for you
AppConfig.application.url #=> http://localhost:3000/

Copyright © 2008/2011 Wojciech Piekutowski, Hubert Łępicki, Piotr Tynecki released under the MIT license

About

Simple configuration framework for Rails applications based on YAML files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •