No commit activity in last 3 years
No release in over 3 years
Implements a standard way of using yml files to configure gems.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

GemConfigurator

Provides a simple, uniform way to configure a gem with a yaml file. Designed to work within a Rails app.

Installation

Add this line to your application's Gemfile:

gem 'gem_configurator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gem_configurator

Usage

Include the module into a class that you wish to configure via YAML.

  class Foo
    include GemConfigurator
    
    def initialize()
      configure
      ...
    end
    
    ...
  end

Within your rails app, place a config file in the /config directory. The config file's name must match the class's name. For example, to configure Foo, name the file foo.yml.

Example yaml file:

  development:
    [setting name]: [setting value]
    ...
  
  test: 
    ...

On instantiation, the settings for your current environment are placed in an instance variable called @settings. Retrieve the settings with @settings['setting name']

If you want to use symbol keys for your settings, change your yaml file to this:

  development:
    :[setting name]: [setting value]
    ...  

Then retrieve the setting with @settings[:setting name]

The gem parses ERB, so if you're storing configuration settings in environment variables, this works:

  development:
    redis_uri: <%= ENV['redis_uri'] %>

Default Settings

If you want your object to have default settings, simply define a default_settings instance method.

  class Foo
    include GemConfigurator
    
    def initialize()
      configure
      ...
    end
    
    def default_settings
      {:setting_name => setting_value}
    end

Default settings will be merged with any settings defined in the YAML file. YAML file settings will overwrite a default setting of the same name.

Contributing

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