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.