Class: ActiveSupport::Callbacks::CallbackChain
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Enumerable
#as_json, #compact_blank, #exclude?, #excluding, #including, #index_by, #index_with, #many?, #pick, #pluck, #sum, #without
Constructor Details
#initialize(name, config) ⇒ CallbackChain
Returns a new instance of CallbackChain.
525
526
527
528
529
530
531
532
533
534
|
# File 'lib/active_support/callbacks.rb', line 525
def initialize(name, config)
@name = name
@config = {
scope: [:kind],
terminator: default_terminator
}.merge!(config)
@chain = []
@callbacks = nil
@mutex = Mutex.new
end
|
Instance Attribute Details
Returns the value of attribute config.
523
524
525
|
# File 'lib/active_support/callbacks.rb', line 523
def config
@config
end
|
Returns the value of attribute name.
523
524
525
|
# File 'lib/active_support/callbacks.rb', line 523
def name
@name
end
|
Instance Method Details
#append(*callbacks) ⇒ Object
571
572
573
|
# File 'lib/active_support/callbacks.rb', line 571
def append(*callbacks)
callbacks.each { |c| append_one(c) }
end
|
550
551
552
553
554
|
# File 'lib/active_support/callbacks.rb', line 550
def clear
@callbacks = nil
@chain.clear
self
end
|
562
563
564
565
566
567
568
569
|
# File 'lib/active_support/callbacks.rb', line 562
def compile
@callbacks || @mutex.synchronize do
final_sequence = CallbackSequence.new
@callbacks ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
callback.apply callback_sequence
end
end
end
|
#delete(o) ⇒ Object
545
546
547
548
|
# File 'lib/active_support/callbacks.rb', line 545
def delete(o)
@callbacks = nil
@chain.delete(o)
end
|
#each(&block) ⇒ Object
536
|
# File 'lib/active_support/callbacks.rb', line 536
def each(&block); @chain.each(&block); end
|
#empty? ⇒ Boolean
538
|
# File 'lib/active_support/callbacks.rb', line 538
def empty?; @chain.empty?; end
|
537
|
# File 'lib/active_support/callbacks.rb', line 537
def index(o); @chain.index(o); end
|
#initialize_copy(other) ⇒ Object
556
557
558
559
560
|
# File 'lib/active_support/callbacks.rb', line 556
def initialize_copy(other)
@callbacks = nil
@chain = other.chain.dup
@mutex = Mutex.new
end
|
#insert(index, o) ⇒ Object
540
541
542
543
|
# File 'lib/active_support/callbacks.rb', line 540
def insert(index, o)
@callbacks = nil
@chain.insert(index, o)
end
|
#prepend(*callbacks) ⇒ Object
575
576
577
|
# File 'lib/active_support/callbacks.rb', line 575
def prepend(*callbacks)
callbacks.each { |c| prepend_one(c) }
end
|