Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Small and flexible configuration toolkit inspired i.a. by Sinatra settings.
branch: master



Konfigurator is a small and flexible configuration toolkit, which allow you to configure your apps, classes or modules with DSL-style or Sinatra-like settings.


You can install Konfigurator simply using rubygems:

sudo gem install konfigurator

…or install it from source:

git clone git://
cd konfigurator
rake install

Sinatra-like configuration

Konfigurator is very easy to use. Take a look at simple example.

class MyClass do 
  include Konfigurator

  set :foo, "bar"
  enable :bar
  disable :bla

  configure :production do
    enable :bla
    set :spam, "eggs!"

Now you can get configured options directly from your class: # => "bar" # => true
MyClass.bla # => false

… or when current environment is set to :production:

MyClass.bla  # => true
MyClass.spam # => "eggs!"

All settings are also available from objects via #settings method:

obj = # => "bar" # => true

Remember! when option is not set then NoMethodError will be raised after try to get it direcly from class, eg:

MyObject.set :exist
MyObject.exist      # => true
MyObject.not_exist  # => will raise NoMethodError

DSL-style configuration

Not there is also possible to use nice-looking DSL syntax provided by Konfigurator::DSL. It allow you to configure your apps/classes such like here:

Foo.configure do 
  host ""
  port 8080
  password "secret"

But what's important in this kind of configuration, you have to define all possible options first. You can define configuration attributes easy using #attr_config (or #attr_setting alias).

class Foo 
  include Konfigurator::DSL

  attr_config :host, :port
  attr_config :password

Other use cases behave almost the same as with Konfigurator::Simple: # => ""
Foo.port # => 8080

Foo.env :production
Foo.configure :production do 
  host ""
  port 80

foo = # => ""
foo.settings.port # => 80

Configuring Rails 3 application

You can easily mix Konfigurator with your Rails 3 app. Add this line to your config/application.rb:

require 'konfigurator/railtie'

… and now you can set your own configuration, eg:

module MyApp
  class Application < Rails::Application
    set :foo, "Foo"
    set :bat, "Bar"
    enable :foobar

    # ...

Now you can use it in controllers…

class UsersController
  def index
    if settings.foobar and == "Foo"
      # ...

… and views…

<h1><%= %></h1>
<p><%= %></p>

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 Kriss 'nu7hatch' Kowalik. See LICENSE for details.

Something went wrong with that request. Please try again.