Project

konfig

0.0
No commit activity in last 3 years
No release in over 3 years
Automatically loads yaml config files and makes them available to your rails app.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

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[: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 © 2010 Starr Horne. See LICENSE for details.