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.
571
572
573
574
575
576
577
578
579
580
581
|
# File '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
Returns the value of attribute config.
569
570
571
|
# File 'lib/active_support/callbacks.rb', line 569
def config
@config
end
|
Returns the value of attribute name.
569
570
571
|
# File 'lib/active_support/callbacks.rb', line 569
def name
@name
end
|
Instance Method Details
#append(*callbacks) ⇒ Object
631
632
633
|
# File 'lib/active_support/callbacks.rb', line 631
def append(*callbacks)
callbacks.each { |c| append_one(c) }
end
|
599
600
601
602
603
604
|
# File 'lib/active_support/callbacks.rb', line 599
def clear
@all_callbacks = nil
@single_callbacks.clear
@chain.clear
self
end
|
#compile(type) ⇒ Object
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
|
# File '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
|
#delete(o) ⇒ Object
593
594
595
596
597
|
# File 'lib/active_support/callbacks.rb', line 593
def delete(o)
@all_callbacks = nil
@single_callbacks.clear
@chain.delete(o)
end
|
#each(&block) ⇒ Object
583
|
# File 'lib/active_support/callbacks.rb', line 583
def each(&block); @chain.each(&block); end
|
#empty? ⇒ Boolean
585
|
# File 'lib/active_support/callbacks.rb', line 585
def empty?; @chain.empty?; end
|
584
|
# File 'lib/active_support/callbacks.rb', line 584
def index(o); @chain.index(o); end
|
#initialize_copy(other) ⇒ Object
606
607
608
609
610
611
|
# File 'lib/active_support/callbacks.rb', line 606
def initialize_copy(other)
@all_callbacks = nil
@single_callbacks = {}
@chain = other.chain.dup
@mutex = Mutex.new
end
|
#insert(index, o) ⇒ Object
587
588
589
590
591
|
# File 'lib/active_support/callbacks.rb', line 587
def insert(index, o)
@all_callbacks = nil
@single_callbacks.clear
@chain.insert(index, o)
end
|
#prepend(*callbacks) ⇒ Object
635
636
637
|
# File 'lib/active_support/callbacks.rb', line 635
def prepend(*callbacks)
callbacks.each { |c| prepend_one(c) }
end
|