123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::Callbacks::CallbackChain

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: activesupport/lib/active_support/callbacks.rb

Class Method Summary

Instance Attribute Summary

::Enumerable - Included

#many?

Returns true if the enumerable has more than 1 element.

Instance Method Summary

::Enumerable - Included

#compact_blank

Returns a new ::Array without the blank items.

#exclude?

The negative of the Enumerable#include?.

#excluding

Returns a copy of the enumerable excluding the specified elements.

#in_order_of

Returns a new ::Array where the order has been set to that provided in the series, based on the key of the objects in the original enumerable.

#including

Returns a new array that includes the passed elements.

#index_by

Convert an enumerable to a hash, using the block result as the key and the element as the value.

#index_with

Convert an enumerable to a hash, using the element as the key and the block result as the value.

#maximum

Calculates the maximum from the extracted elements.

#minimum

Calculates the minimum from the extracted elements.

#pick

Extract the given key from the first element in the enumerable.

#pluck

Extract the given key from each element in the enumerable.

#sole

Returns the sole item in the enumerable.

#without
#as_json

::ActiveSupport::EnumerableCoreExt::Constants - Included

Constructor Details

.new(name, config) ⇒ CallbackChain

[ GitHub ]

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

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

Instance Attribute Details

#chain (readonly, protected)

[ GitHub ]

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

attr_reader :chain

#config (readonly)

[ GitHub ]

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

attr_reader :name, :config

#empty?Boolean (readonly)

[ GitHub ]

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

def empty?;       @chain.empty?; end

#name (readonly)

[ GitHub ]

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

attr_reader :name, :config

Instance Method Details

#append(*callbacks)

[ GitHub ]

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

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

#append_one(callback) (private)

[ GitHub ]

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

def append_one(callback)
  @all_callbacks = nil
  @single_callbacks.clear
  remove_duplicates(callback)
  @chain.push(callback)
end

#clear

[ GitHub ]

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

def clear
  @all_callbacks = nil
  @single_callbacks.clear
  @chain.clear
  self
end

#compile(type)

[ GitHub ]

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

def compile(type)
  if type.nil?
    @all_callbacks || @mutex.synchronize do
      final_sequence = CallbackSequence.new
      @all_callbacks ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
        callback.apply(callback_sequence)
      end
    end
  else
    @single_callbacks[type] || @mutex.synchronize do
      final_sequence = CallbackSequence.new
      @single_callbacks[type] ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
        type == callback.kind ? callback.apply(callback_sequence) : callback_sequence
      end
    end
  end
end

#default_terminator (private)

[ GitHub ]

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

def default_terminator
  Proc.new do |target, result_lambda|
    terminate = true
    catch(:abort) do
      result_lambda.call
      terminate = false
    end
    terminate
  end
end

#delete(o)

[ GitHub ]

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

def delete(o)
  @all_callbacks = nil
  @single_callbacks.clear
  @chain.delete(o)
end

#each(&block)

[ GitHub ]

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

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

#index(o)

[ GitHub ]

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

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

#initialize_copy(other)

[ GitHub ]

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

def initialize_copy(other)
  @all_callbacks = nil
  @single_callbacks = {}
  @chain     = other.chain.dup
  @mutex     = Mutex.new
end

#insert(index, o)

[ GitHub ]

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

def insert(index, o)
  @all_callbacks = nil
  @single_callbacks.clear
  @chain.insert(index, o)
end

#prepend(*callbacks)

[ GitHub ]

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

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

#prepend_one(callback) (private)

[ GitHub ]

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

def prepend_one(callback)
  @all_callbacks = nil
  @single_callbacks.clear
  remove_duplicates(callback)
  @chain.unshift(callback)
end

#remove_duplicates(callback) (private)

[ GitHub ]

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

def remove_duplicates(callback)
  @all_callbacks = nil
  @single_callbacks.clear
  @chain.delete_if { |c| callback.duplicates?(c) }
end