Class: ActiveSupport::Callbacks::CallbackChain

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
activesupport/lib/active_support/callbacks.rb

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


473
474
475
476
477
478
479
480
481
# File 'activesupport/lib/active_support/callbacks.rb', line 473

def initialize(name, config)
  @name = name
  @config = {
    :scope => [ :kind ]
  }.merge!(config)
  @chain = []
  @callbacks = nil
  @mutex = Mutex.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


471
472
473
# File 'activesupport/lib/active_support/callbacks.rb', line 471

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name


471
472
473
# File 'activesupport/lib/active_support/callbacks.rb', line 471

def name
  @name
end

Instance Method Details

#append(*callbacks) ⇒ Object


517
518
519
# File 'activesupport/lib/active_support/callbacks.rb', line 517

def append(*callbacks)
  callbacks.each { |c| append_one(c) }
end

#clearObject


497
498
499
500
501
# File 'activesupport/lib/active_support/callbacks.rb', line 497

def clear
  @callbacks = nil
  @chain.clear
  self
end

#compileObject


509
510
511
512
513
514
515
# File 'activesupport/lib/active_support/callbacks.rb', line 509

def compile
  @callbacks || @mutex.synchronize do
    @callbacks ||= @chain.reverse.inject(Filters::ENDING) do |chain, callback|
      callback.apply chain
    end
  end
end

#delete(o) ⇒ Object


492
493
494
495
# File 'activesupport/lib/active_support/callbacks.rb', line 492

def delete(o)
  @callbacks = nil
  @chain.delete(o)
end

#each(&block) ⇒ Object


483
# File 'activesupport/lib/active_support/callbacks.rb', line 483

def each(&block); @chain.each(&block); end

#empty?Boolean

Returns:

  • (Boolean)

485
# File 'activesupport/lib/active_support/callbacks.rb', line 485

def empty?;       @chain.empty?; end

#index(o) ⇒ Object


484
# File 'activesupport/lib/active_support/callbacks.rb', line 484

def index(o);     @chain.index(o); end

#initialize_copy(other) ⇒ Object


503
504
505
506
507
# File 'activesupport/lib/active_support/callbacks.rb', line 503

def initialize_copy(other)
  @callbacks = nil
  @chain     = other.chain.dup
  @mutex     = Mutex.new
end

#insert(index, o) ⇒ Object


487
488
489
490
# File 'activesupport/lib/active_support/callbacks.rb', line 487

def insert(index, o)
  @callbacks = nil
  @chain.insert(index, o)
end

#prepend(*callbacks) ⇒ Object


521
522
523
# File 'activesupport/lib/active_support/callbacks.rb', line 521

def prepend(*callbacks)
  callbacks.each { |c| prepend_one(c) }
end