Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simplest YAML Backed Application Wide Configuration (AppConfig)
Branch: master
Pull request Compare This branch is 19 commits behind PhilT:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
LICENSE
README.md
Rakefile
app_conf.gemspec

README.md

AppConf

Simplest YAML Backed Application Wide Configuration (AppConfig)

Installation

gem install app_conf

Example

config.yml --- fullname: Joe Bloggs user: name: Joe

other.yml --- user: address: street: 1 Some Road

Code: AppConf.load('config.yml', 'other.yml') AppConf.fullname -> 'Joe Blogs' AppConf.user.name -> 'Joe' AppConf.user[:address]['street'] -> '1 Some Road'

Syntax

Load multiple files at once: AppConf.load(*filenames)

Or individually: AppConf.load(filename1) AppConf.load(filename2)

Use either method calls or hash syntax: AppConf.fullname AppConf[:fullname] AppConf['fullname']

Infinitely nested keys: AppConf.multiple.nested.keys

Override existing values: AppConf.loaded.from.yaml = 'can override' AppConf['loaded']['from']['yaml'] = 'can override'

Set new values: AppConf.non_existing_value = 'can set'

Clear entire tree: AppConf.clear

Returns nil for non-existent keys: AppConf.non_existing -> nil AppConf.non_existing.name -> NoMethodError: undefined method 'name' for nil:NilClass

Not dependent on Rails but easy to use with it. For example: AppConf.load('config.yml', "#{Rails.env}.yml")

Other stuff

  • Works with Ruby 1.9.2
  • No gem dependencies
  • Fully tested with MiniTest::Spec
  • Packaged as a Gem on RubyGems.org

Why

  • Because I wanted to write the simplest useful app config possible
  • Others are either too simple or incomplete, lack documentation or aren't Gem installable
  • Because I can :-)

Known Issues

Cannot assign values to unknown nested keys because they return nil AppConf.non_existing.name = 'bla' -> NoMethodError: undefined method 'name=' for nil:NilClass

Something went wrong with that request. Please try again.