/block_configurable

A little mixin to make your classes and modules configurable

Primary LanguageRubyMIT LicenseMIT

BlockConfigurable

Build Status Code Climate Gem Version

A little mixin to make your classes and modules configurable using either single statements or blocks.

Installation

Install as a standalone gem:

gem install block_configurable

Or include into your Gemfile:

gem 'block_configurable', '~> 0.10.0'

Usage

Set up your class (or module). Only parameters explicitly listed will be available for configuration.

class MyClass
  include BlockConfigurable

  configurable :param_with_default_value, 'A default!'
  configurable :param_without_default_value
  configurable :another_one
end

Configure it:

MyClass.configure do |c|
  c.param_without_default_value = 'A value now!'
  c.another_one = 'My values, my rules'
end

# or

MyClass.configuration.another_one = 'My values, my rules'

Read configuration:

MyClass.configuration.param_with_default_value
#=> 'A default!'

MyClass.configuration.another_one
#=> 'My values, my rules'