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.


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

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


515
516
517
# File 'lib/active_support/callbacks.rb', line 515

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name


515
516
517
# File 'lib/active_support/callbacks.rb', line 515

def name
  @name
end

Instance Method Details

#append(*callbacks) ⇒ Object


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

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

#clearObject


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

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

#compileObject


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

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


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

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

#each(&block) ⇒ Object


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

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

#empty?Boolean

Returns:

  • (Boolean)

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

def empty?;       @chain.empty?; end

#index(o) ⇒ Object


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

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

#initialize_copy(other) ⇒ Object


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

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

#insert(index, o) ⇒ Object


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

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

#prepend(*callbacks) ⇒ Object


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

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