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 Method Summary collapse

Constructor Details

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

:nodoc:



467
468
469
470
471
472
473
474
# File 'lib/active_support/callbacks.rb', line 467

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



481
482
483
484
# File 'lib/active_support/callbacks.rb', line 481

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

#around(call_template, user_conditions) ⇒ Object



486
487
488
# File 'lib/active_support/callbacks.rb', line 486

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

#before(&before) ⇒ Object



476
477
478
479
# File 'lib/active_support/callbacks.rb', line 476

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

#expand_call_template(arg, block) ⇒ Object



502
503
504
# File 'lib/active_support/callbacks.rb', line 502

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

#final?Boolean

Returns:

  • (Boolean)


498
499
500
# File 'lib/active_support/callbacks.rb', line 498

def final?
  !@call_template
end

#invoke_after(arg) ⇒ Object



510
511
512
# File 'lib/active_support/callbacks.rb', line 510

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

#invoke_before(arg) ⇒ Object



506
507
508
# File 'lib/active_support/callbacks.rb', line 506

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

#nestedObject



494
495
496
# File 'lib/active_support/callbacks.rb', line 494

def nested
  @nested
end

#skip?(arg) ⇒ Boolean

Returns:

  • (Boolean)


490
491
492
# File 'lib/active_support/callbacks.rb', line 490

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