2009-03-29 02:52:46 -04:00
|
|
|
require 'active_support/core_ext/hash/deep_merge'
|
|
|
|
|
2005-12-15 15:03:23 -05:00
|
|
|
module ActiveSupport
|
|
|
|
class OptionMerger #:nodoc:
|
2007-09-27 06:41:12 -04:00
|
|
|
instance_methods.each do |method|
|
2007-09-13 20:34:43 -04:00
|
|
|
undef_method(method) if method !~ /^(__|instance_eval|class|object_id)/
|
2005-12-15 15:03:23 -05:00
|
|
|
end
|
2007-09-27 06:41:12 -04:00
|
|
|
|
2005-12-15 15:03:23 -05:00
|
|
|
def initialize(context, options)
|
|
|
|
@context, @options = context, options
|
|
|
|
end
|
2007-09-27 06:41:12 -04:00
|
|
|
|
2005-12-15 15:03:23 -05:00
|
|
|
private
|
|
|
|
def method_missing(method, *arguments, &block)
|
2008-11-15 10:48:14 -05:00
|
|
|
if arguments.last.is_a?(Proc)
|
|
|
|
proc = arguments.pop
|
|
|
|
arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) }
|
|
|
|
else
|
|
|
|
arguments << (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup)
|
|
|
|
end
|
|
|
|
|
2008-08-31 16:15:26 -04:00
|
|
|
@context.__send__(method, *arguments, &block)
|
2005-12-15 15:03:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|