Permalink
Browse files

push merge code to the callback itself

  • Loading branch information...
1 parent 91e002e commit 929658c98d48eeba7f65ec4afb0f8cbedadaf270 @tenderlove tenderlove committed May 10, 2013
Showing with 10 additions and 18 deletions.
  1. +10 −18 activesupport/lib/active_support/callbacks.rb
@@ -120,12 +120,16 @@ def deprecate_per_key_option(options)
end
end
- def initialize_copy(other)
- super
- @options = {
- :if => other.options[:if].dup,
- :unless => other.options[:unless].dup
+ def merge(chain, new_options)
+ _options = {
+ :if => @options[:if].dup,
+ :unless => @options[:unless].dup
}
+
+ _options[:if].concat Array(new_options.fetch(:unless, []))
+ _options[:unless].concat Array(new_options.fetch(:if, []))
+
+ self.class.new chain, @filter, @kind, _options
end
def normalize_options!(options)
@@ -150,16 +154,6 @@ def duplicates?(other)
end
end
- def _update_filter(filter_options, new_options)
- filter_options[:if].concat(Array(new_options[:unless])) if new_options.key?(:unless)
- filter_options[:unless].concat(Array(new_options[:if])) if new_options.key?(:if)
- end
-
- def recompile!(_options)
- deprecate_per_key_option(_options)
- _update_filter(self.options, _options)
- end
-
# Wraps code with filter
def apply(next_callback)
user_conditions = conditions_lambdas
@@ -492,10 +486,8 @@ def skip_callback(name, *filter_list, &block)
filter = chain.find {|c| c.matches?(type, filter) }
if filter && options.any?
- new_filter = filter.dup
- new_filter.chain = chain
+ new_filter = filter.merge(chain, options)
chain.insert(chain.index(filter), new_filter)
- new_filter.recompile!(options)
end
chain.delete(filter)

0 comments on commit 929658c

Please sign in to comment.