Changeset 9225
- Timestamp:
- 04/04/08 20:26:42 (8 months ago)
- Files:
-
- trunk/actionpack/lib/action_controller/filters.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations/association_collection.rb (modified) (1 diff)
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/callbacks.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/filters.rb
r9080 r9225 386 386 def call(controller, &block) 387 387 if should_run_callback?(controller) 388 proc = filter_responds_to_before_and_after? ? around_proc : method 389 evaluate_method(proc, controller, &block) 388 method = filter_responds_to_before_and_after? ? around_proc : self.method 389 390 # For around_filter do |controller, action| 391 if method.is_a?(Proc) && method.arity == 2 392 evaluate_method(method, controller, block) 393 else 394 evaluate_method(method, controller, &block) 395 end 390 396 else 391 397 block.call trunk/activerecord/lib/active_record/associations/association_collection.rb
r9200 r9225 241 241 def callback(method, record) 242 242 callbacks_for(method).each do |callback| 243 case callback 244 when Symbol 245 @owner.send(callback, record) 246 when Proc, Method 247 callback.call(@owner, record) 248 else 249 if callback.respond_to?(method) 250 callback.send(method, @owner, record) 251 else 252 raise ActiveRecordError, "Callbacks must be a symbol denoting the method to call, a string to be evaluated, a block to be invoked, or an object responding to the callback method." 253 end 254 end 255 end 256 end 257 243 ActiveSupport::Callbacks::Callback.new(method, callback, record).call(@owner, record) 244 end 245 end 246 258 247 def callbacks_for(callback_name) 259 248 full_callback_name = "#{callback_name}_for_#{@reflection.name}" trunk/activesupport/CHANGELOG
r9221 r9225 1 1 *SVN* 2 3 * Modified ActiveSupport::Callbacks::Callback#call to accept multiple arguments. 2 4 3 5 * Time #yesterday and #tomorrow behave correctly crossing DST boundary. Closes #7399 [sblackstone] trunk/activesupport/lib/active_support/callbacks.rb
r9055 r9225 150 150 end 151 151 152 def call( object, &block)153 evaluate_method(method, object, &block) if should_run_callback?(object)152 def call(*args, &block) 153 evaluate_method(method, *args, &block) if should_run_callback?(*args) 154 154 rescue LocalJumpError 155 155 raise ArgumentError, … … 159 159 160 160 private 161 def evaluate_method(method, object, &block)161 def evaluate_method(method, *args, &block) 162 162 case method 163 163 when Symbol 164 object.send(method, &block) 164 object = args.shift 165 object.send(method, *args, &block) 165 166 when String 166 eval(method, object.instance_eval { binding })167 eval(method, args.first.instance_eval { binding }) 167 168 when Proc, Method 168 case method.arity 169 when -1, 1 170 method.call(object, &block) 171 when 2 172 method.call(object, block) 173 else 174 raise ArgumentError, 'Callback blocks must take one or two arguments.' 175 end 169 method.call(*args, &block) 176 170 else 177 171 if method.respond_to?(kind) 178 method.send(kind, object, &block)172 method.send(kind, *args, &block) 179 173 else 180 174 raise ArgumentError, … … 185 179 end 186 180 187 def should_run_callback?( object)181 def should_run_callback?(*args) 188 182 if options[:if] 189 evaluate_method(options[:if], object)183 evaluate_method(options[:if], *args) 190 184 elsif options[:unless] 191 !evaluate_method(options[:unless], object)185 !evaluate_method(options[:unless], *args) 192 186 else 193 187 true