ruby-conf

Simple way to do ruby config DSL

Install

gem install ruby-conf

Gemfile

gem "ruby-conf"

Examples

RubyConf.define :godzilla do
  mothra 'sucks'
  godzilla 'rocks'
end

> RubyConf.godzilla.mothra
=> "sucks" 
> RubyConf.godzilla.godzilla
=> "rocks" 

RubyConf.define "monkey" , :as => 'MyBonobo' do
 has_legs true
 number_arms 2
 number_legs 2
 name 'Nancy' , 'Drew'
 age 34

 # make sure to pass a lambda and not a do block
 # do blocks chain configurations (see below)
 number_of_bananas_eaten lambda { 
   BanannaChomper.lookup("nancy.bananas").count
 }
end
MyBonobo.name                     # ['Nancy' , 'Drew']
MyBonobo.number_of_bananas_eaten  # execute proc
MyBonobo.number_legs              # 2
RubyConf[:monkey][:age]           # 34
...

Anonymous configurations

config = RubyConf.define do
  favorite_color 'blue'
end
config.favorite_color             # "blue"

Configuration chaining

RubyConf.define "rails", :as => :RailsConfig do
  production do
    database "rails_prod"
    host "localhost"
  end
  staging do
    database "rails_staging"
    host "localhost"
  end
end
RailsConfig.production.database  # "rails_prod"
RailsConfig.staging.database     # "rails_staging"

Inheritance

RubyConf.define "rails", :as => :RailsConfig do
  defaults do
    host "localhost"
    username "godzilla"
    password "mothra"
  end

  development :inherits => defaults do
    database "development"
  end

  test :inherits => defaults do
    database "test"
    username "biollante"
    password "destroygodzilla"
  end

  production :inherits => defaults do
    database "production"
    host "killmothra.net"
    password "ilovemothra"
  end
end
RailsConfig.development.database      # "development"
RailsConfig.development.username      # "godzilla
RailsConfig.development.password      # "mothra"
RailsConfig.production.username       # "godzilla"
RailsConfig.production.password       # "ilovemothra"

Using ruby-conf with Rails

Ruby-conf can be used with Rails.  Restart the server after setting up config values.

Contributing to ruby-conf

Copyright © 2012 Blazing Cloud inc. See LICENSE.txt for further details.