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/rails/rails/issues/18011
Instance Attribute Summary collapse
-
#nested ⇒ Object
readonly
Returns the value of attribute nested.
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
A new instance of CallbackSequence.
- #invoke_after(arg) ⇒ Object
- #invoke_before(arg) ⇒ Object
- #skip?(arg) ⇒ Boolean
Constructor Details
#initialize(nested = nil, call_template = nil, user_conditions = nil) ⇒ CallbackSequence
Returns a new instance of CallbackSequence.
558 559 560 561 562 563 564 565 |
# File 'activesupport/lib/active_support/callbacks.rb', line 558 def initialize(nested = nil, call_template = nil, user_conditions = nil) @nested = nested @call_template = call_template @user_conditions = user_conditions @before = [] @after = [] end |
Instance Attribute Details
#nested ⇒ Object (readonly)
Returns the value of attribute nested
585 586 587 |
# File 'activesupport/lib/active_support/callbacks.rb', line 585 def nested @nested end |
Instance Method Details
#after(&after) ⇒ Object
572 573 574 575 |
# File 'activesupport/lib/active_support/callbacks.rb', line 572 def after(&after) @after.push(after) self end |
#around(call_template, user_conditions) ⇒ Object
577 578 579 |
# File 'activesupport/lib/active_support/callbacks.rb', line 577 def around(call_template, user_conditions) CallbackSequence.new(self, call_template, user_conditions) end |
#before(&before) ⇒ Object
567 568 569 570 |
# File 'activesupport/lib/active_support/callbacks.rb', line 567 def before(&before) @before.unshift(before) self end |
#expand_call_template(arg, block) ⇒ Object
591 592 593 |
# File 'activesupport/lib/active_support/callbacks.rb', line 591 def (arg, block) @call_template.(arg.target, arg.value, block) end |
#final? ⇒ Boolean
587 588 589 |
# File 'activesupport/lib/active_support/callbacks.rb', line 587 def final? !@call_template end |
#invoke_after(arg) ⇒ Object
599 600 601 |
# File 'activesupport/lib/active_support/callbacks.rb', line 599 def invoke_after(arg) @after.each { |a| a.call(arg) } end |
#invoke_before(arg) ⇒ Object
595 596 597 |
# File 'activesupport/lib/active_support/callbacks.rb', line 595 def invoke_before(arg) @before.each { |b| b.call(arg) } end |
#skip?(arg) ⇒ Boolean
581 582 583 |
# File 'activesupport/lib/active_support/callbacks.rb', line 581 def skip?(arg) arg.halted || !@user_conditions.all? { |c| c.call(arg.target, arg.value) } end |