Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Configuration manager for rails apps

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 konfig.gemspec
README.rdoc

konfig: Config file management for rails apps

Every app needs to store seldom-changing data like facebook access keys, or SMTP settings, or Authorize.net credentials.

Usually, you just stick it in an intializer. Or if you're feeling really sassy, you might make a yml file and create an initializer to load it. It's kind of a pain, and it's kind of messy.

Konfig gives you a better, easier way to manage these config files.

Overview

It works like this:

> mkdir ./config/settings
> cat "bar: baz" > ./config/settings/foo.yml
> rails console

irb(main):001:0> Konfig[:foo][:bar]

=> "baz"

Installation

Add this to your Gemfile

gem konfig

Then make sure that config/settings exsits. That's it. Konfig automagically loads all .yml files in the RAILS_ROOT/config/settings directory. It makes them accessible via the Konfig module. ie. Konfig[:filename][:key]

Raw power

There are often times when you need to make the same config data avalible in sevaral different forms.

Konfig makes this easy by letting you embed ruby in your yaml templates. This code has access to all of the data in the template.

# config/settings/example.yml

one: 1
two: 2
one_plus_two: `data[:one] + data[:two]`

Helpers

You can also access helper methods in your embedded code.

# config/settings/example.yml

# You might use this for a list of <select> options
colors:
  - ["Red", "#ff0000"]
  - ["Green", "#00ff00"]
  - ["Blue", "#0000ff"]

# This returns {"#ff0000" => "Red", ...etc }
color_names: `names_by_value(:colors)`

Rails 3

Konfig only works with Rails 3

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests 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 Starr Horne. See LICENSE for details.

Something went wrong with that request. Please try again.