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)
|
|
|
|
merge_argument_options! arguments
|
2007-09-27 06:41:12 -04:00
|
|
|
@context.send!(method, *arguments, &block)
|
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 merge_argument_options!(arguments)
|
2006-04-26 17:49:41 -04:00
|
|
|
arguments << if arguments.last.respond_to? :to_hash
|
|
|
|
@options.merge(arguments.pop)
|
2005-12-15 15:03:23 -05:00
|
|
|
else
|
|
|
|
@options.dup
|
2007-09-27 06:41:12 -04:00
|
|
|
end
|
2005-12-15 15:03:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|