DotConfig Build Status

This gem is only compatible with Ruby 1.9.

The DotConfig gem give you access to your configuration via the dot syntax. You instantiate DotConfig::Configuration with a Hash and you will retrieve the values in calling the key as method name.

Installation

Add this line to your application's Gemfile:

gem 'dot_config'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dot_config

Usage

# Instantiate the configuration with the shortcut:
app_config = DotConfig.new(language: 'Ruby', framework: 'Ruby on Rails')

app_config.language  #=> 'Ruby'
app_config.framework #=> 'Ruby on Rails'
app_config.version   #=> NoMethodError: undefined method `version' for #<DotConfig::Configuration:0x007fb1fed55dd8>

# Instantiate the configuration without the shortcut:
app_config = DotConfig::Configuration.new(config: { language: 'Ruby', framework: 'Ruby on Rails' })

# Instantiate the configuration with an instance of DotConfig::Configuration:
app_config = DotConfig::Configuration.new
app_config.config = { language: 'Ruby', framework: 'Ruby on Rails' }

# Instantiate the configuration with a YAML file:
app_config = DotConfig.new('PATH/TO/YOUR/FILE.yml')

# Use a nested Hash:
app_config = DotConfig.new(language: { ruby: 'Ruby on Rails' })

app_config.language      #=> #<DotConfig::Configuration:0x007fb1fed55dd8>
app_config.language.ruby #=> 'Ruby on Rails'

# Enable the modification:
app_config = DotConfig.new({ language: 'Ruby', framework: 'Ruby on Rails' }, true)
# or
app_config = DotConfig.new(true)
app_config.config = { language: 'Ruby', framework: 'Ruby on Rails' }

app_config.language  #=> 'Ruby'
app_config.language = 'Python'
app_config.language  #=> 'Python'

# Export the configuration:
app_config = DotConfig.new(language: { ruby: 'Ruby on Rails' })

app_config.to_hash #=> { language: { ruby: 'Ruby on Rails' } }

Documentation

To get more information about this gem, please visit RubyDoc.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request