2007-01-22 14:43:50 +01:00
|
|
|
module ActiveSupport
|
|
|
|
class OptionMerger #:nodoc:
|
2007-12-21 08:48:59 +01:00
|
|
|
instance_methods.each do |method|
|
|
|
|
undef_method(method) if method !~ /^(__|instance_eval|class|object_id)/
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def initialize(context, options)
|
|
|
|
@context, @options = context, options
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
private
|
|
|
|
def method_missing(method, *arguments, &block)
|
|
|
|
merge_argument_options! arguments
|
2007-12-21 08:48:59 +01:00
|
|
|
@context.send!(method, *arguments, &block)
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def merge_argument_options!(arguments)
|
2007-02-09 09:04:31 +01:00
|
|
|
arguments << if arguments.last.respond_to? :to_hash
|
|
|
|
@options.merge(arguments.pop)
|
2007-01-22 14:43:50 +01:00
|
|
|
else
|
|
|
|
@options.dup
|
2007-12-21 08:48:59 +01:00
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|