Included Modules

Class/Module Index [+]

Quicksearch

Mongoid::Callbacks

This module contains all the callback hooks for Mongoid.

Constants

CALLBACKS

Public Instance Methods

callback_executable?(kind) click to toggle source

Is the provided type of callback executable by this document?

@example Is the callback executable?

document.callback_executable?(:save)

@param [ Symbol ] kin The type of callback.

@return [ true, false ] If the callback can be executed.

@since 3.0.6

# File lib/mongoid/callbacks.rb, line 51
def callback_executable?(kind)
  respond_to?("_#{kind}_callbacks")
end
in_callback_state?(kind) click to toggle source

Is the document currently in a state that could potentially require callbacks to be executed?

@example Is the document in a callback state?

document.in_callback_state?(:update)

@param [ Symbol ] kind The callback kind.

@return [ true, false ] If the document is in a callback state.

@since 3.1.0

# File lib/mongoid/callbacks.rb, line 66
def in_callback_state?(kind)
  [ :create, :destroy ].include?(kind) || new_record? || flagged_for_destroy? || changed?
end
run_after_callbacks(*kinds) click to toggle source

Run only the after callbacks for the specific event.

@note ActiveSupport does not allow this type of behaviour by default, so

Mongoid has to get around it and implement itself.

@example Run only the after save callbacks.

model.run_after_callbacks(:save)

@param [ Array<Symbol> ] kinds The events that are occurring.

@return [ Object ] The result of the chain executing.

@since 3.0.0

# File lib/mongoid/callbacks.rb, line 83
def run_after_callbacks(*kinds)
  kinds.each do |kind|
    run_targeted_callbacks(:after, kind)
  end
end
run_before_callbacks(*kinds) click to toggle source

Run only the before callbacks for the specific event.

@note ActiveSupport does not allow this type of behaviour by default, so

Mongoid has to get around it and implement itself.

@example Run only the before save callbacks.

model.run_before_callbacks(:save, :create)

@param [ Array<Symbol> ] kinds The events that are occurring.

@return [ Object ] The result of the chain executing.

@since 3.0.0

# File lib/mongoid/callbacks.rb, line 102
def run_before_callbacks(*kinds)
  kinds.each do |kind|
    run_targeted_callbacks(:before, kind)
  end
end
run_callbacks(kind, *args, &block) click to toggle source

Run the callbacks for the document. This overrides active support's functionality to cascade callbacks to embedded documents that have been flagged as such.

@example Run the callbacks.

run_callbacks :save do
  save!
end

@param [ Symbol ] kind The type of callback to execute. @param [ Array ] *args Any options.

@return [ Document ] The document

@since 2.3.0

# File lib/mongoid/callbacks.rb, line 123
def run_callbacks(kind, *args, &block)
  cascadable_children(kind).each do |child|
    unless child.run_callbacks(child_callback_type(kind, child), *args)
      return false
    end
  end
  callback_executable?(kind) ? super(kind, *args, &block) : true
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.