diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-10 14:12:56 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-10 14:12:56 -0700 |
commit | 929658c98d48eeba7f65ec4afb0f8cbedadaf270 (patch) | |
tree | 0fca11057933609c2a984b8a45b50ef1c542e8bd /activesupport/lib/active_support | |
parent | 91e002e31eb50329a5936dab3286b41571868653 (diff) | |
download | rails-929658c98d48eeba7f65ec4afb0f8cbedadaf270.tar.gz rails-929658c98d48eeba7f65ec4afb0f8cbedadaf270.tar.bz2 rails-929658c98d48eeba7f65ec4afb0f8cbedadaf270.zip |
push merge code to the callback itself
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/callbacks.rb | 28 |
1 files changed, 10 insertions, 18 deletions
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) |