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(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:
473 474 475 476 477 478 479 480 |
# File 'lib/active_support/callbacks.rb', line 473 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
487 488 489 490 |
# File 'lib/active_support/callbacks.rb', line 487 def after(&after) @after.push(after) self end |
#around(call_template, user_conditions) ⇒ Object
492 493 494 |
# File 'lib/active_support/callbacks.rb', line 492 def around(call_template, user_conditions) CallbackSequence.new(self, call_template, user_conditions) end |
#before(&before) ⇒ Object
482 483 484 485 |
# File 'lib/active_support/callbacks.rb', line 482 def before(&before) @before.unshift(before) self end |
#expand_call_template(arg, block) ⇒ Object
508 509 510 |
# File 'lib/active_support/callbacks.rb', line 508 def (arg, block) @call_template.(arg.target, arg.value, block) end |
#final? ⇒ Boolean
504 505 506 |
# File 'lib/active_support/callbacks.rb', line 504 def final? !@call_template end |
#invoke_after(arg) ⇒ Object
516 517 518 |
# File 'lib/active_support/callbacks.rb', line 516 def invoke_after(arg) @after.each { |a| a.call(arg) } end |
#invoke_before(arg) ⇒ Object
512 513 514 |
# File 'lib/active_support/callbacks.rb', line 512 def invoke_before(arg) @before.each { |b| b.call(arg) } end |
#nested ⇒ Object
500 501 502 |
# File 'lib/active_support/callbacks.rb', line 500 def nested @nested end |
#skip?(arg) ⇒ Boolean
496 497 498 |
# File 'lib/active_support/callbacks.rb', line 496 def skip?(arg) arg.halted || !@user_conditions.all? { |c| c.call(arg.target, arg.value) } end |