Class: ActiveSupport::Callbacks::CallbackChain
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
|
|
| Inherits: | Object |
| Defined in: | activesupport/lib/active_support/callbacks.rb |
Constant Summary
-
DEFAULT_TERMINATOR =
# File 'activesupport/lib/active_support/callbacks.rb', line 741DefaultTerminator.new.freeze
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)
- #freeze
- #index(o)
- #initialize_copy(other)
- #insert(index, o)
- #prepend(*callbacks)
- #append_one(callback) private
- #compile_sequence(type) 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 622
def initialize(name, config) @name = name @config = { scope: [:kind], terminator: DEFAULT_TERMINATOR }.merge!(config) @config[:terminator] = Ractors.try_shareable_proc(@config[:terminator]) if @config[:terminator].is_a?(Proc) @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 701
attr_reader :chain
#config (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 620
attr_reader :name, :config
#empty? ⇒ Boolean (readonly)
[ GitHub ]
# File 'activesupport/lib/active_support/callbacks.rb', line 637
def empty?; @chain.empty?; end
#name (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 620
attr_reader :name, :config
Instance Method Details
#append(*callbacks)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 679
def append(*callbacks) callbacks.each { |c| append_one(c) } end
#append_one(callback) (private)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 711
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 651
def clear @all_callbacks = nil @single_callbacks.clear @chain.clear self end
#compile(type)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 665
def compile(type) if frozen? type.nil? ? (@all_callbacks || compile_sequence(nil)) : (@single_callbacks[type] || compile_sequence(type)) elsif type.nil? @all_callbacks || @mutex.synchronize do @all_callbacks ||= compile_sequence(nil) end else @single_callbacks[type] || @mutex.synchronize do @single_callbacks[type] ||= compile_sequence(type) end end end
#compile_sequence(type) (private)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 704
def compile_sequence(type) final_sequence = CallbackSequence.new @chain.reverse.inject(final_sequence) do |callback_sequence, callback| type.nil? || type == callback.kind ? callback.apply(callback_sequence) : callback_sequence end end
#delete(o)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 645
def delete(o) @all_callbacks = nil @single_callbacks.clear @chain.delete(o) end
#each(&block)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 635
def each(&block); @chain.each(&block); end
#freeze
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 687
def freeze return self if frozen? @chain.each(&:freeze) compile(nil) CALLBACK_FILTER_TYPES.each { |type| compile(type) } @chain.freeze @config.freeze @single_callbacks.freeze @mutex = nil super end
#index(o)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 636
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 683
def prepend(*callbacks) callbacks.each { |c| prepend_one(c) } end
#prepend_one(callback) (private)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 718
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 725
def remove_duplicates(callback) @all_callbacks = nil @single_callbacks.clear @chain.delete_if { |c| callback.duplicates?(c) } end