Class: ActiveSupport::Callbacks::CallbackChain
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | activesupport/lib/active_support/callbacks.rb |
Class Method Summary
- .new(name, config) ⇒ CallbackChain constructor
Instance Attribute Summary
- #config readonly
- #empty? ⇒ Boolean readonly
- #name readonly
- #chain readonly protected
::Enumerable
- Included
#many? | Returns |
Instance Method Summary
- #append(*callbacks)
- #clear
- #compile(type)
- #delete(o)
- #each(&block)
- #index(o)
- #initialize_copy(other)
- #insert(index, o)
- #prepend(*callbacks)
- #append_one(callback) private
- #default_terminator private
- #prepend_one(callback) private
- #remove_duplicates(callback) private
::Enumerable
- Included
#compact_blank | Returns a new |
#exclude? | The negative of the |
#excluding | Returns a copy of the enumerable excluding the specified elements. |
#in_order_of | Returns a new |
#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 | Alias for Enumerable#excluding. |
#as_json |
::ActiveSupport::EnumerableCoreExt::Constants
- Included
Constructor Details
.new(name, config) ⇒ CallbackChain
# File 'activesupport/lib/active_support/callbacks.rb', line 571
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 640
attr_reader :chain
#config (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 569
attr_reader :name, :config
#empty? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'activesupport/lib/active_support/callbacks.rb', line 585
def empty?; @chain.empty?; end
#name (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 569
attr_reader :name, :config
Instance Method Details
#append(*callbacks)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 631
def append(*callbacks) callbacks.each { |c| append_one(c) } end
#append_one(callback) (private)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 643
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 599
def clear @all_callbacks = nil @single_callbacks.clear @chain.clear self end
#compile(type)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 613
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 663
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 593
def delete(o) @all_callbacks = nil @single_callbacks.clear @chain.delete(o) end
#each(&block)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 583
def each(&block); @chain.each(&block); end
#index(o)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 584
def index(o); @chain.index(o); end
#initialize_copy(other)
[ GitHub ]#insert(index, o)
[ GitHub ]#prepend(*callbacks)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 635
def prepend(*callbacks) callbacks.each { |c| prepend_one(c) } end
#prepend_one(callback) (private)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 650
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 657
def remove_duplicates(callback) @all_callbacks = nil @single_callbacks.clear @chain.delete_if { |c| callback.duplicates?(c) } end