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?, #sum
Constructor Details
#initialize(name, config) ⇒ CallbackChain
Returns a new instance of CallbackChain.
476
477
478
479
480
481
482
483
484
|
# File 'lib/active_support/callbacks.rb', line 476
def initialize(name, config)
@name = name
@config = {
:scope => [ :kind ]
}.merge!(config)
@chain = []
@callbacks = nil
@mutex = Mutex.new
end
|
Instance Attribute Details
Returns the value of attribute config.
474
475
476
|
# File 'lib/active_support/callbacks.rb', line 474
def config
@config
end
|
Returns the value of attribute name.
474
475
476
|
# File 'lib/active_support/callbacks.rb', line 474
def name
@name
end
|
Instance Method Details
#append(*callbacks) ⇒ Object
520
521
522
|
# File 'lib/active_support/callbacks.rb', line 520
def append(*callbacks)
callbacks.each { |c| append_one(c) }
end
|
500
501
502
503
504
|
# File 'lib/active_support/callbacks.rb', line 500
def clear
@callbacks = nil
@chain.clear
self
end
|
512
513
514
515
516
517
518
|
# File 'lib/active_support/callbacks.rb', line 512
def compile
@callbacks || @mutex.synchronize do
@callbacks ||= @chain.reverse.inject(Filters::ENDING) do |chain, callback|
callback.apply chain
end
end
end
|
#delete(o) ⇒ Object
495
496
497
498
|
# File 'lib/active_support/callbacks.rb', line 495
def delete(o)
@callbacks = nil
@chain.delete(o)
end
|
#each(&block) ⇒ Object
486
|
# File 'lib/active_support/callbacks.rb', line 486
def each(&block); @chain.each(&block); end
|
#empty? ⇒ Boolean
488
|
# File 'lib/active_support/callbacks.rb', line 488
def empty?; @chain.empty?; end
|
487
|
# File 'lib/active_support/callbacks.rb', line 487
def index(o); @chain.index(o); end
|
#initialize_copy(other) ⇒ Object
506
507
508
509
510
|
# File 'lib/active_support/callbacks.rb', line 506
def initialize_copy(other)
@callbacks = nil
@chain = other.chain.dup
@mutex = Mutex.new
end
|
#insert(index, o) ⇒ Object
490
491
492
493
|
# File 'lib/active_support/callbacks.rb', line 490
def insert(index, o)
@callbacks = nil
@chain.insert(index, o)
end
|
#prepend(*callbacks) ⇒ Object
524
525
526
|
# File 'lib/active_support/callbacks.rb', line 524
def prepend(*callbacks)
callbacks.each { |c| prepend_one(c) }
end
|