Skip to content

Instantly share code, notes, and snippets.

@youngbrioche
Created February 15, 2011 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save youngbrioche/827406 to your computer and use it in GitHub Desktop.
Save youngbrioche/827406 to your computer and use it in GitHub Desktop.
Small configuration DSL
module Foo
module Configuration
require 'ostruct'
extend ActiveSupport::Concern
included do
#
end
module ClassMethods
def method_missing(method_name, *args)
@config ||= OpenStruct.new
if method_name.to_s.match(/^.+=$/)
@config.send(method_name, args.first)
else
@config.send(method_name)
end
end
def configure
yield self
end
end
end
end
# Usage
module App
include Foo::Configuration
end
App.configure do |config|
config.test_value = :test
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment