Class: ActiveSupport::Callbacks::CallbackSequence
- Defined in:
- activesupport/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/quails/quails/issues/18011
Instance Method Summary collapse
- #after(&after) ⇒ Object
- #around(call_template, user_conditions) ⇒ Object
- #before(&before) ⇒ Object
- #expand_call_template(arg, block) ⇒ Object
- #final? ⇒ Boolean
-
#initialize(nested = nil, call_template = nil, user_conditions = nil) ⇒ CallbackSequence
constructor
:nodoc:.
- #invoke_after(arg) ⇒ Object
- #invoke_before(arg) ⇒ Object
- #nested ⇒ Object
- #skip?(arg) ⇒ Boolean
Constructor Details
#initialize(nested = nil, call_template = nil, user_conditions = nil) ⇒ CallbackSequence
:nodoc:
468 469 470 471 472 473 474 475 |
# File 'activesupport/lib/active_support/callbacks.rb', line 468 def initialize(nested = nil, call_template = nil, user_conditions = nil) @nested = nested @call_template = call_template @user_conditions = user_conditions @before = [] @after = [] end |
Instance Method Details
#after(&after) ⇒ Object
482 483 484 485 |
# File 'activesupport/lib/active_support/callbacks.rb', line 482 def after(&after) @after.push(after) self end |
#around(call_template, user_conditions) ⇒ Object
487 488 489 |
# File 'activesupport/lib/active_support/callbacks.rb', line 487 def around(call_template, user_conditions) CallbackSequence.new(self, call_template, user_conditions) end |
#before(&before) ⇒ Object
477 478 479 480 |
# File 'activesupport/lib/active_support/callbacks.rb', line 477 def before(&before) @before.unshift(before) self end |
#expand_call_template(arg, block) ⇒ Object
503 504 505 |
# File 'activesupport/lib/active_support/callbacks.rb', line 503 def (arg, block) @call_template.(arg.target, arg.value, block) end |
#final? ⇒ Boolean
499 500 501 |
# File 'activesupport/lib/active_support/callbacks.rb', line 499 def final? !@call_template end |
#invoke_after(arg) ⇒ Object
511 512 513 |
# File 'activesupport/lib/active_support/callbacks.rb', line 511 def invoke_after(arg) @after.each { |a| a.call(arg) } end |
#invoke_before(arg) ⇒ Object
507 508 509 |
# File 'activesupport/lib/active_support/callbacks.rb', line 507 def invoke_before(arg) @before.each { |b| b.call(arg) } end |
#nested ⇒ Object
495 496 497 |
# File 'activesupport/lib/active_support/callbacks.rb', line 495 def nested @nested end |
#skip?(arg) ⇒ Boolean
491 492 493 |
# File 'activesupport/lib/active_support/callbacks.rb', line 491 def skip?(arg) arg.halted || !@user_conditions.all? { |c| c.call(arg.target, arg.value) } end |