Skip to content
This repository

Gem for storing configurations

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 features
Octocat-spinner-32 lib
Octocat-spinner-32 .coveralls.yml
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .ruby-gemset
Octocat-spinner-32 .ruby-version
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
Octocat-spinner-32 config-me.gemspec

Config Me Build Status Coverage Status Dependency Status Gem Version

Gem provides convenient tool for storing file based configurations.


gem install config-me

In Rails 3, add this to your Gemfile and run the bundle command.

gem "config-me"

Defining config

ConfigMe do
  foo do
    bar 'test'

  sample 666

Reading config # => 'test'
ConfigMe.sample  # => 666     # => an instance of ConfigMe::Node which have some useful methods

ConfigMe.test    # => will raise exception ConfigMe::UndefinedSetting

Changing existing config

Let's define config for a start:

ConfigMe do
  foo do
    bar 'test'

Then we could change value of the existing setting: = 'sample'

Or add new setting: = 'test'

The only restriction is that we couldn't add setting to not existing node: = 5 # => will raise exception ConfigMe::UndefinedSetting 'test' for ''

But we could define it using blocks structure: do
  test do
    cool 5
end # => 5    # => will raise exception ConfigMe::UndefinedSetting, because we redefined whole node


Every time you define configuration in some namespace, the default is :production, but you can provide the namespace name you want:

ConfigMe do
  foo 'bar'

ConfigMe(:development) do
  foo 'foo'
end               # => 'bar'
ConfigMe(:production).foo  # => 'bar'
ConfigMe(:development).foo # => 'foo'

Importing from hash

If you have a some hash:

my_hash = { :foo => { :bar => 'test' } }

Your could import it:

ConfigMe :hash => my_hash # => 'test'

Importing from yaml

ConfigMe :yaml => '/path/to/my/yaml/configuration'

Dumping config to hash

ConfigMe do
  foo do
    bar 'test'

ConfigMe.to_hash     # => { :foo => { :bar => 'test' } } # => { :bar => 'test' }

Auto calling procs

By default if you assign proc to setting value, then it will be executed while reading. I mean:

ConfigMe do
  foo proc { 5 + 5 }
  bar proc { |count| count * 2 }
end    # => 10 # => 4

But you could disable this feature:

ConfigMe::Defaults.auto_calling_proc = false

Rails 3 integration

This will be implemented in separate gem config-me-rails3 very soon.

Something went wrong with that request. Please try again.