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.



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

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.



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

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#append(*callbacks) ⇒ Object



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

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

#clearObject



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

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

#compileObject



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

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



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

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

#each(&block) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?;       @chain.empty?; end

#index(o) ⇒ Object



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

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

#initialize_copy(other) ⇒ Object



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

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

#insert(index, o) ⇒ Object



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

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

#prepend(*callbacks) ⇒ Object



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

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