ConfigFun: Beautiful configurations for your projects and gems
http://github.com/gammons/config_fun
DESCRIPTION:
Does your gem or project need the user to create or add configuration to it? Use ConfigFun to allow them to easily configure your gem, in a quick, terse and painless way!
SYNOPSIS:
Adding ConfigFun to your project is super easy. Include the config_fun gem as part of your gem's dependencies.
Say you need to write a configuration that allows the user to add their account information, name, password, and some IMAP information. With ConfigFun, the configuration could look like this:
account "personal" do
name "grant"
password "bungalow"
imap do
server "imap.gmail.com"
ssl true
end
end
To parse this configuration, you'd simply Say the following:
config = ConfigFun.parse!(File.read(account_information_file))
..and the config variable would include a sweet hash of all the info the user provided!
config == {:account=> {:password => "bungalow", :imap => {:ssl => true, :server => "imap.gmail.com"}, :name => "grant"}}
DETAILS:
Arrays
if ConfigFun encounters a block twice within the same context, it will create an array.
user do
room "123"
end
user do
room "456"
end
The resulting hash will have a :user
key with an array of :room
s as the value.
{:user=>[{:room=>"123"}, {:room=>"456"}]}
An important caveat
Blocks do not take any paramters. You may be tempted to do something like the following:
user "Bob" do
room "123"
end
ConfigFun will not be able to parse this, because there is no equivalent hash it can boil down to.
The correct way to write the above code for ConfigFun is as follows:
user do
name "bob"
room "123"
end
REQUIREMENTS:
- None!
- Tested against ruby 1.8.7 and 1.9.2.
INSTALL:
gem install config_fun
AUTHORS:
- Grant Ammons
LICENSE:
(The MIT License)
Copyright (c) 2010 Grant Ammons ([email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.