Class: ActiveSupport::Callbacks::CallbackSequence

Inherits:
Object
  • Object
show all
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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nested = nil, call_template = nil, user_conditions = nil) ⇒ CallbackSequence

:nodoc:



519
520
521
522
523
524
525
526
# File 'lib/active_support/callbacks.rb', line 519

def initialize(nested = nil, call_template = nil, user_conditions = nil)
  @nested = nested
  @call_template = call_template
  @user_conditions = user_conditions

  @before = nil
  @after = nil
end

Instance Attribute Details

#nestedObject (readonly)

Returns the value of attribute nested.



548
549
550
# File 'lib/active_support/callbacks.rb', line 548

def nested
  @nested
end

Instance Method Details

#after(after) ⇒ Object



534
535
536
537
538
# File 'lib/active_support/callbacks.rb', line 534

def after(after)
  @after ||= []
  @after.push(after)
  self
end

#around(call_template, user_conditions) ⇒ Object



540
541
542
# File 'lib/active_support/callbacks.rb', line 540

def around(call_template, user_conditions)
  CallbackSequence.new(self, call_template, user_conditions)
end

#before(before) ⇒ Object



528
529
530
531
532
# File 'lib/active_support/callbacks.rb', line 528

def before(before)
  @before ||= []
  @before.unshift(before)
  self
end

#expand_call_template(arg, block) ⇒ Object



554
555
556
# File 'lib/active_support/callbacks.rb', line 554

def expand_call_template(arg, block)
  @call_template.expand(arg.target, arg.value, block)
end

#final?Boolean

Returns:

  • (Boolean)


550
551
552
# File 'lib/active_support/callbacks.rb', line 550

def final?
  !@call_template
end

#invoke_after(arg) ⇒ Object



562
563
564
# File 'lib/active_support/callbacks.rb', line 562

def invoke_after(arg)
  @after&.each { |a| a.call(arg) }
end

#invoke_before(arg) ⇒ Object



558
559
560
# File 'lib/active_support/callbacks.rb', line 558

def invoke_before(arg)
  @before&.each { |b| b.call(arg) }
end

#skip?(arg) ⇒ Boolean

Returns:

  • (Boolean)


544
545
546
# File 'lib/active_support/callbacks.rb', line 544

def skip?(arg)
  arg.halted || !@user_conditions.all? { |c| c.call(arg.target, arg.value) }
end