Class: ActiveSupport::Callbacks::CallbackSequence
- Defined in:
- lib/active_support/callbacks.rb
Overview
Execute before and after filters in a sequence instead of chaining them with nested lambda calls, see: github.com/rails/rails/issues/18011
Instance Method Summary collapse
- #after(&after) ⇒ Object
- #around(&around) ⇒ Object
- #before(&before) ⇒ Object
- #call(arg) ⇒ Object
-
#initialize(&call) ⇒ CallbackSequence
constructor
A new instance of CallbackSequence.
Constructor Details
#initialize(&call) ⇒ CallbackSequence
Returns a new instance of CallbackSequence.
429 430 431 432 433 |
# File 'lib/active_support/callbacks.rb', line 429 def initialize(&call) @call = call @before = [] @after = [] end |
Instance Method Details
#after(&after) ⇒ Object
440 441 442 443 |
# File 'lib/active_support/callbacks.rb', line 440 def after(&after) @after.push(after) self end |
#around(&around) ⇒ Object
445 446 447 448 449 450 451 |
# File 'lib/active_support/callbacks.rb', line 445 def around(&around) CallbackSequence.new do |arg| around.call(arg) { self.call(arg) } end end |
#before(&before) ⇒ Object
435 436 437 438 |
# File 'lib/active_support/callbacks.rb', line 435 def before(&before) @before.unshift(before) self end |
#call(arg) ⇒ Object
453 454 455 456 457 458 |
# File 'lib/active_support/callbacks.rb', line 453 def call(arg) @before.each { |b| b.call(arg) } value = @call.call(arg) @after.each { |a| a.call(arg) } value end |