I got tired of writing configuration classes for everything I do, and packaged it all up in a tiny gem: Construct.

Highlights

OpenStruct-style access to key-value pairs. <cr:code lang=“ruby”>config.offices = [‘Sydney’, ‘Tacoma’]</cr:code>

Nested structures are easy to handle. <cr:code lang=“ruby”> config.fruits = { :banana => ‘slightly radioactive’, :apple => ‘safe’ } config.fruits.banana # => ‘slightly radioactive’ </cr:code>

Overridable, self-documenting schemas for default values. <cr:code lang=“ruby”> config.define(:address, :default => ‘1 North College St’) config.address # => ‘1 North College St’ config.address = ‘Urnud’ config.address # => ‘Urnud’ </cr:code>

Straightforward YAML saving and loading. <cr:code lang=“ruby”>config.to_yaml; Construct.load(yaml)</cr:code>

Define whatever methods you like on your config. <cr:code lang=“ruby”> class Config < Construct def fooo foo + ‘o’ end end </cr:code>

It’s available as a gem: gem install construct

Post a Comment

Comments are moderated. Links have nofollow. Seriously, spammers, give it a rest.

Please avoid writing anything here unless you're a computer. This is also a trap:

Supports Github-flavored Markdown, including [links](http://foo.com/), *emphasis*, _underline_, `code`, and > blockquotes. Use ```clj on its own line to start an (e.g.) Clojure code block, and ``` to end the block.