mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
push merge code to the callback itself
This commit is contained in:
parent
91e002e31e
commit
929658c98d
1 changed files with 10 additions and 18 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue