Class: ActiveSupport::Callbacks::CallbackChain
Overview
An Array with a compile method.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Enumerable
#as_json, #exclude?, #index_by, #many?, #pluck, #sum, #without
Constructor Details
#initialize(name, config) ⇒ CallbackChain
Returns a new instance of CallbackChain.
467
468
469
470
471
472
473
474
475
476
|
# File 'lib/active_support/callbacks.rb', line 467
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.
465
466
467
|
# File 'lib/active_support/callbacks.rb', line 465
def config
@config
end
|
Returns the value of attribute name.
465
466
467
|
# File 'lib/active_support/callbacks.rb', line 465
def name
@name
end
|
Instance Method Details
#append(*callbacks) ⇒ Object
513
514
515
|
# File 'lib/active_support/callbacks.rb', line 513
def append(*callbacks)
callbacks.each { |c| append_one(c) }
end
|
492
493
494
495
496
|
# File 'lib/active_support/callbacks.rb', line 492
def clear
@callbacks = nil
@chain.clear
self
end
|
504
505
506
507
508
509
510
511
|
# File 'lib/active_support/callbacks.rb', line 504
def compile
@callbacks || @mutex.synchronize do
final_sequence = CallbackSequence.new { |env| Filters::ENDING.call(env) }
@callbacks ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
callback.apply callback_sequence
end
end
end
|
#delete(o) ⇒ Object
487
488
489
490
|
# File 'lib/active_support/callbacks.rb', line 487
def delete(o)
@callbacks = nil
@chain.delete(o)
end
|
#each(&block) ⇒ Object
478
|
# File 'lib/active_support/callbacks.rb', line 478
def each(&block); @chain.each(&block); end
|
#empty? ⇒ Boolean
480
|
# File 'lib/active_support/callbacks.rb', line 480
def empty?; @chain.empty?; end
|
479
|
# File 'lib/active_support/callbacks.rb', line 479
def index(o); @chain.index(o); end
|
#initialize_copy(other) ⇒ Object
498
499
500
501
502
|
# File 'lib/active_support/callbacks.rb', line 498
def initialize_copy(other)
@callbacks = nil
@chain = other.chain.dup
@mutex = Mutex.new
end
|
#insert(index, o) ⇒ Object
482
483
484
485
|
# File 'lib/active_support/callbacks.rb', line 482
def insert(index, o)
@callbacks = nil
@chain.insert(index, o)
end
|
#prepend(*callbacks) ⇒ Object
517
518
519
|
# File 'lib/active_support/callbacks.rb', line 517
def prepend(*callbacks)
callbacks.each { |c| prepend_one(c) }
end
|