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¶ ↑
Copyright © 2010 Starr Horne. See LICENSE for details.