Skip to content
This repository
Browse code

do not keep a reference to the chain in the callback objects

  • Loading branch information...
commit b97ff316ec6d3fa962dc804d5aeb83aa81b2d847 1 parent f0a9f81
Aaron Patterson tenderlove authored

Showing 1 changed file with 10 additions and 12 deletions. Show diff stats Hide diff stats

  1. +10 12 activesupport/lib/active_support/callbacks.rb
22 activesupport/lib/active_support/callbacks.rb
@@ -95,13 +95,15 @@ module Filters
95 95
96 96 class Callback #:nodoc:#
97 97 def self.build(chain, filter, kind, options)
98   - new chain, filter, kind, options
  98 + new chain.name, filter, kind, options, chain.config
99 99 end
100 100
101   - attr_accessor :chain, :kind, :options
  101 + attr_accessor :kind, :options, :name
  102 + attr_reader :chain_config
102 103
103   - def initialize(chain, filter, kind, options)
104   - @chain = chain
  104 + def initialize(name, filter, kind, options, chain_config)
  105 + @chain_config = chain_config
  106 + @name = name
105 107 @kind = kind
106 108 @filter = filter
107 109 @options = options
@@ -131,7 +133,7 @@ def merge(chain, new_options)
131 133 _options[:if].concat Array(new_options.fetch(:unless, []))
132 134 _options[:unless].concat Array(new_options.fetch(:if, []))
133 135
134   - self.class.new chain, @filter, @kind, _options
  136 + self.class.build chain, @filter, @kind, _options
135 137 end
136 138
137 139 def normalize_options!(options)
@@ -139,10 +141,6 @@ def normalize_options!(options)
139 141 options[:unless] = Array(options[:unless])
140 142 end
141 143
142   - def name
143   - chain.name
144   - end
145   -
146 144 def matches?(_kind, _filter)
147 145 @kind == _kind && filter == _filter
148 146 end
@@ -163,7 +161,7 @@ def apply(next_callback)
163 161
164 162 case kind
165 163 when :before
166   - halted_lambda = eval "lambda { |result| #{chain.config[:terminator]} }"
  164 + halted_lambda = eval "lambda { |result| #{chain_config[:terminator]} }"
167 165 lambda { |env|
168 166 target = env.target
169 167 value = env.value
@@ -179,7 +177,7 @@ def apply(next_callback)
179 177 next_callback.call env
180 178 }
181 179 when :after
182   - if chain.config[:skip_after_callbacks_if_terminated]
  180 + if chain_config[:skip_after_callbacks_if_terminated]
183 181 lambda { |env|
184 182 env = next_callback.call env
185 183 target = env.target
@@ -271,7 +269,7 @@ def make_lambda(filter)
271 269 }
272 270 end
273 271 else
274   - scopes = Array(chain.config[:scope])
  272 + scopes = Array(chain_config[:scope])
275 273 method_to_call = scopes.map{ |s| public_send(s) }.join("_")
276 274
277 275 lambda { |target, _, &blk|

0 comments on commit b97ff31

Please sign in to comment.
Something went wrong with that request. Please try again.