Class: ActiveSupport::Callbacks::CallbackChain

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

Overview

An Array with a compile method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #exclude?, #index_by, #many?, #pluck, #sum, #without

Constructor Details

#initialize(name, config) ⇒ CallbackChain

Returns a new instance of CallbackChain.



521
522
523
524
525
526
527
528
529
530
# File 'lib/active_support/callbacks.rb', line 521

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.



519
520
521
# File 'lib/active_support/callbacks.rb', line 519

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



519
520
521
# File 'lib/active_support/callbacks.rb', line 519

def name
  @name
end

Instance Method Details

#append(*callbacks) ⇒ Object



567
568
569
# File 'lib/active_support/callbacks.rb', line 567

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

#clearObject



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

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

#compileObject



558
559
560
561
562
563
564
565
# File 'lib/active_support/callbacks.rb', line 558

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



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

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

#each(&block) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?;       @chain.empty?; end

#index(o) ⇒ Object



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

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

#initialize_copy(other) ⇒ Object



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

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

#insert(index, o) ⇒ Object



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

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

#prepend(*callbacks) ⇒ Object



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

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