Skip to content

Instantly share code, notes, and snippets.

@tors
Forked from youngbrioche/configuration.rb
Created June 5, 2012 10:36
Show Gist options
  • Select an option

  • Save tors/2874321 to your computer and use it in GitHub Desktop.

Select an option

Save tors/2874321 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