I’ve just released ruby-configurable 1.0.1, a library that gives any
plain Ruby class a configuration object.
Code:
https://bitbucket.org/krbullock/configurable (Hg repo)
GitHub - krbullock/configurable: Make your Ruby class or app configurable with a simple mixin. (Git mirror—thanks hg-git!)
Documentation:
http://handtools.rubyforge.org/ruby-configurable/
Why this implementation?
- Provides a simple class macro to declare allowed settings and their
default values. - Settings are accessible via simple method calls, or array-style or
hash-style. - Unknown configuration keys are rejected.
- Handles nested configuration keys (e.g. MyClass.config.foo.bar =
:baz). - Convertible to a hash-argument-friendly form, for passing to methods
that take ‘keyword’ arguments. - No dependencies outside core Ruby.
Current known shortcomings:
- Doesn’t separate configuration of a subclass from that of its
superclass. - No way to programmatically add allowed settings after the initial
declaration.