From 929658c98d48eeba7f65ec4afb0f8cbedadaf270 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 10 May 2013 14:12:56 -0700 Subject: push merge code to the callback itself --- activesupport/lib/active_support/callbacks.rb | 28 ++++++++++----------------- 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'activesupport/lib/active_support/callbacks.rb') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index b7c0f1d484..0370a27f32 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -120,12 +120,16 @@ module ActiveSupport 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 @@ module ActiveSupport 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 @@ module ActiveSupport 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) -- cgit v1.2.3