Class: ActiveSupport::Callbacks::CallbackChain

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_support/callbacks.rb

Overview

:nodoc:#

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #exclude?, #excluding, #including, #index_by, #index_with, #many?, #pluck, #sum, #without

Constructor Details

#initialize(name, config) ⇒ CallbackChain

Returns a new instance of CallbackChain.



526
527
528
529
530
531
532
533
534
535
# File 'lib/active_support/callbacks.rb', line 526

def initialize(name, config)
  @name = name
  @config = {
    scope: [:kind],
    terminator: default_terminator
  }.merge!(config)
  @chain = []
  @callbacks = nil
  @mutex = Mutex.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



524
525
526
# File 'lib/active_support/callbacks.rb', line 524

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



524
525
526
# File 'lib/active_support/callbacks.rb', line 524

def name
  @name
end

Instance Method Details

#append(*callbacks) ⇒ Object



572
573
574
# File 'lib/active_support/callbacks.rb', line 572

def append(*callbacks)
  callbacks.each { |c| append_one(c) }
end

#clearObject



551
552
553
554
555
# File 'lib/active_support/callbacks.rb', line 551

def clear
  @callbacks = nil
  @chain.clear
  self
end

#compileObject



563
564
565
566
567
568
569
570
# File 'lib/active_support/callbacks.rb', line 563

def compile
  @callbacks || @mutex.synchronize do
    final_sequence = CallbackSequence.new
    @callbacks ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
      callback.apply callback_sequence
    end
  end
end

#delete(o) ⇒ Object



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

def delete(o)
  @callbacks = nil
  @chain.delete(o)
end

#each(&block) ⇒ Object



537
# File 'lib/active_support/callbacks.rb', line 537

def each(&block); @chain.each(&block); end

#empty?Boolean

Returns:

  • (Boolean)


539
# File 'lib/active_support/callbacks.rb', line 539

def empty?;       @chain.empty?; end

#index(o) ⇒ Object



538
# File 'lib/active_support/callbacks.rb', line 538

def index(o);     @chain.index(o); end

#initialize_copy(other) ⇒ Object



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

def initialize_copy(other)
  @callbacks = nil
  @chain     = other.chain.dup
  @mutex     = Mutex.new
end

#insert(index, o) ⇒ Object



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

def insert(index, o)
  @callbacks = nil
  @chain.insert(index, o)
end

#prepend(*callbacks) ⇒ Object



576
577
578
# File 'lib/active_support/callbacks.rb', line 576

def prepend(*callbacks)
  callbacks.each { |c| prepend_one(c) }
end