Class: ActiveSupport::Callbacks::CallbackChain
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Enumerable
#as_json, #compact_blank, #exclude?, #excluding, #in_order_of, #including, #index_by, #index_with, #many?, #maximum, #minimum, #pick, #pluck, #sole
Constructor Details
#initialize(name, config) ⇒ CallbackChain
Returns a new instance of CallbackChain.
611
612
613
614
615
616
617
618
619
620
621
|
# File '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
Returns the value of attribute config.
609
610
611
|
# File 'lib/active_support/callbacks.rb', line 609
def config
@config
end
|
Returns the value of attribute name.
609
610
611
|
# File 'lib/active_support/callbacks.rb', line 609
def name
@name
end
|
Instance Method Details
#append(*callbacks) ⇒ Object
671
672
673
|
# File 'lib/active_support/callbacks.rb', line 671
def append(*callbacks)
callbacks.each { |c| append_one(c) }
end
|
639
640
641
642
643
644
|
# File 'lib/active_support/callbacks.rb', line 639
def clear
@all_callbacks = nil
@single_callbacks.clear
@chain.clear
self
end
|
#compile(type) ⇒ Object
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
|
# File '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
|
#delete(o) ⇒ Object
633
634
635
636
637
|
# File 'lib/active_support/callbacks.rb', line 633
def delete(o)
@all_callbacks = nil
@single_callbacks.clear
@chain.delete(o)
end
|
#each(&block) ⇒ Object
623
|
# File 'lib/active_support/callbacks.rb', line 623
def each(&block); @chain.each(&block); end
|
#empty? ⇒ Boolean
625
|
# File 'lib/active_support/callbacks.rb', line 625
def empty?; @chain.empty?; end
|
624
|
# File 'lib/active_support/callbacks.rb', line 624
def index(o); @chain.index(o); end
|
#initialize_copy(other) ⇒ Object
646
647
648
649
650
651
|
# File '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) ⇒ Object
627
628
629
630
631
|
# File 'lib/active_support/callbacks.rb', line 627
def insert(index, o)
@all_callbacks = nil
@single_callbacks.clear
@chain.insert(index, o)
end
|
#prepend(*callbacks) ⇒ Object
675
676
677
|
# File 'lib/active_support/callbacks.rb', line 675
def prepend(*callbacks)
callbacks.each { |c| prepend_one(c) }
end
|