Class: ActiveSupport::Callbacks::CallbackChain
- Inherits:
-
Object
- Object
- ActiveSupport::Callbacks::CallbackChain
show all
- Includes:
- Enumerable
- Defined in:
- activesupport/lib/active_support/callbacks.rb
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?, #pluck, #sum, #without
Constructor Details
#initialize(name, config) ⇒ CallbackChain
Returns a new instance of CallbackChain.
523
524
525
526
527
528
529
530
531
532
|
# File 'activesupport/lib/active_support/callbacks.rb', line 523
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
521
522
523
|
# File 'activesupport/lib/active_support/callbacks.rb', line 521
def config
@config
end
|
Returns the value of attribute name
521
522
523
|
# File 'activesupport/lib/active_support/callbacks.rb', line 521
def name
@name
end
|
Instance Method Details
#append(*callbacks) ⇒ Object
569
570
571
|
# File 'activesupport/lib/active_support/callbacks.rb', line 569
def append(*callbacks)
callbacks.each { |c| append_one(c) }
end
|
548
549
550
551
552
|
# File 'activesupport/lib/active_support/callbacks.rb', line 548
def clear
@callbacks = nil
@chain.clear
self
end
|
560
561
562
563
564
565
566
567
|
# File 'activesupport/lib/active_support/callbacks.rb', line 560
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
543
544
545
546
|
# File 'activesupport/lib/active_support/callbacks.rb', line 543
def delete(o)
@callbacks = nil
@chain.delete(o)
end
|
#each(&block) ⇒ Object
534
|
# File 'activesupport/lib/active_support/callbacks.rb', line 534
def each(&block); @chain.each(&block); end
|
#empty? ⇒ Boolean
536
|
# File 'activesupport/lib/active_support/callbacks.rb', line 536
def empty?; @chain.empty?; end
|
535
|
# File 'activesupport/lib/active_support/callbacks.rb', line 535
def index(o); @chain.index(o); end
|
#initialize_copy(other) ⇒ Object
554
555
556
557
558
|
# File 'activesupport/lib/active_support/callbacks.rb', line 554
def initialize_copy(other)
@callbacks = nil
@chain = other.chain.dup
@mutex = Mutex.new
end
|
#insert(index, o) ⇒ Object
538
539
540
541
|
# File 'activesupport/lib/active_support/callbacks.rb', line 538
def insert(index, o)
@callbacks = nil
@chain.insert(index, o)
end
|
#prepend(*callbacks) ⇒ Object
573
574
575
|
# File 'activesupport/lib/active_support/callbacks.rb', line 573
def prepend(*callbacks)
callbacks.each { |c| prepend_one(c) }
end
|