No commit activity in last 3 years
No release in over 3 years
Makes it simple to set arbitrary config key/value pairs on a class.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Simply Configurable¶ ↑

Makes it simple to set arbitrary config key/value pairs on a class.

Synopsis:¶ ↑

require 'simply_configurable'

class Foo

  include SimplyConfigurable

  config :color => 'red'
  config :style => 'awesome'

  def style
    puts "my style is #{config[:style]}"
  end

  class << self
    def color
      puts "my color is #{config['color']}"
    end
  end

end

Foo.color  # prints 'my color is red'
foo = Foo.new
foo.style  # prints 'my style is awesome'

Foo.config  # returns { 'color' => 'red', 'style' => 'awesome' }
Foo.config[:color]  # returns 'red'

Foo.config :color => 'green'
Foo.config['color']  # returns 'green'

Class and Instance Access¶ ↑

The #config method is defined on both the class and its instances, so it may be simply called from either context.

Hash Access¶ ↑

This library uses the HashWithIndifferentAccess class of the ActiveSupport library, allowing you to access/set config values by either symbol or string.

Nesting¶ ↑

Any subclasses of a SimplyConfigurable class will also be SimplyConfigurable. The subclass will inherit all config values from its ancestors, but any values set on the subclass will not overwrite those on the ancestors.

For example:

class Foo
  include SimplyConfigurable

  config :color => 'red'
  config :style => 'awesome'
end

class Bar < Foo
  config :style => 'less awesome'
end

Foo.config[:style]  # returns 'awesome'
Bar.config[:style]  # returns 'less awesome'
Bar.config[:color]  # returns 'red'