Class: ActiveSupport::Callbacks::CallbackSequence

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

Instance Method Summary collapse

Constructor Details

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

:nodoc:



560
561
562
563
564
565
566
567
# File 'activesupport/lib/active_support/callbacks.rb', line 560

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

#nestedObject (readonly)

Returns the value of attribute nested.



587
588
589
# File 'activesupport/lib/active_support/callbacks.rb', line 587

def nested
  @nested
end

Instance Method Details

#after(&after) ⇒ Object



574
575
576
577
# File 'activesupport/lib/active_support/callbacks.rb', line 574

def after(&after)
  @after.push(after)
  self
end

#around(call_template, user_conditions) ⇒ Object



579
580
581
# File 'activesupport/lib/active_support/callbacks.rb', line 579

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

#before(&before) ⇒ Object



569
570
571
572
# File 'activesupport/lib/active_support/callbacks.rb', line 569

def before(&before)
  @before.unshift(before)
  self
end

#expand_call_template(arg, block) ⇒ Object



593
594
595
# File 'activesupport/lib/active_support/callbacks.rb', line 593

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

#final?Boolean

Returns:

  • (Boolean)


589
590
591
# File 'activesupport/lib/active_support/callbacks.rb', line 589

def final?
  !@call_template
end

#invoke_after(arg) ⇒ Object



601
602
603
# File 'activesupport/lib/active_support/callbacks.rb', line 601

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

#invoke_before(arg) ⇒ Object



597
598
599
# File 'activesupport/lib/active_support/callbacks.rb', line 597

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

#skip?(arg) ⇒ Boolean

Returns:

  • (Boolean)


583
584
585
# File 'activesupport/lib/active_support/callbacks.rb', line 583

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