Class: ActiveSupport::Callbacks::CallbackChain

Inherits:
Array show all
Defined in:
lib/active_support/callbacks.rb

Overview

An Array with a compile method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#as_json, #deep_dup, #encode_json, #extract_options!, #fifth, #forty_two, #fourth, #from, #in_groups, #in_groups_of, #second, #split, #third, #to, #to_formatted_s, #to_param, #to_query, #to_sentence, #to_xml, #uniq_by, #uniq_by!, wrap

Constructor Details

#initialize(name, config) ⇒ CallbackChain

Returns a new instance of CallbackChain.



315
316
317
318
319
320
321
# File 'lib/active_support/callbacks.rb', line 315

def initialize(name, config)
  @name = name
  @config = {
    :terminator => "false",
    :scope => [ :kind ]
  }.merge!(config)
end

Instance Attribute Details

#configObject (readonly)

:nodoc:#



313
314
315
# File 'lib/active_support/callbacks.rb', line 313

def config
  @config
end

#nameObject (readonly)

:nodoc:#



313
314
315
# File 'lib/active_support/callbacks.rb', line 313

def name
  @name
end

Instance Method Details

#append(*callbacks) ⇒ Object



335
336
337
# File 'lib/active_support/callbacks.rb', line 335

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

#compileObject



323
324
325
326
327
328
329
330
331
332
333
# File 'lib/active_support/callbacks.rb', line 323

def compile
  method =  ["value = nil", "halted = false"]
  callbacks = "value = !halted && (!block_given? || yield)"
  reverse_each do |callback|
    callbacks = callback.apply(callbacks)
  end
  method << callbacks

  method << "value"
  method.join("\n")
end

#prepend(*callbacks) ⇒ Object



339
340
341
# File 'lib/active_support/callbacks.rb', line 339

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