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?, #sum

Constructor Details

#initialize(name, config) ⇒ CallbackChain

Returns a new instance of CallbackChain.


514
515
516
517
518
519
520
521
522
# File 'lib/active_support/callbacks.rb', line 514

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


512
513
514
# File 'lib/active_support/callbacks.rb', line 512

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name


512
513
514
# File 'lib/active_support/callbacks.rb', line 512

def name
  @name
end

Instance Method Details

#append(*callbacks) ⇒ Object


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

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

#clearObject


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

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

#compileObject


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

def compile
  @callbacks || @mutex.synchronize do
    final_sequence = CallbackSequence.new { |env| Filters::ENDING.call(env) }
    @callbacks ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
      callback.apply callback_sequence
    end
  end
end

#delete(o) ⇒ Object


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

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

#each(&block) ⇒ Object


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

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

#empty?Boolean

Returns:

  • (Boolean)

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

def empty?;       @chain.empty?; end

#index(o) ⇒ Object


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

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

#initialize_copy(other) ⇒ Object


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

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

#insert(index, o) ⇒ Object


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

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

#prepend(*callbacks) ⇒ Object


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

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