123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::Callbacks::CallbackChain

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, ::Enumerable
Inherits: Object
Defined in: activesupport/lib/active_support/callbacks.rb

Overview

An Array with a compile method.

Class Method Summary

Instance Attribute Summary

::Enumerable - Included

#many?

Returns true if the enumerable has more than 1 element.

Instance Method Summary

::Enumerable - Included

#exclude?

The negative of the Enumerable#include?.

#index_by

Convert an enumerable to a hash.

#sum

Calculates a sum from the elements.

Constructor Details

.new(name, config) ⇒ CallbackChain

[ GitHub ]

  
# File 'activesupport/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

#config (readonly)

[ GitHub ]

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

attr_reader :name, :config

#empty?Boolean (readonly)

[ GitHub ]

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

def empty?;       @chain.empty?; end

#name (readonly)

[ GitHub ]

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

attr_reader :name, :config

Instance Method Details

#append(*callbacks)

[ GitHub ]

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

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

#clear

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 541

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

#compile

[ GitHub ]

  
# File 'activesupport/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)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 536

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

#each(&block)

[ GitHub ]

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

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

#index(o)

[ GitHub ]

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

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

#initialize_copy(other)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 547

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

#insert(index, o)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 531

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

#prepend(*callbacks)

[ GitHub ]

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

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