Module: Mongoid::Callbacks

Extended by:
ActiveSupport::Concern
Included in:
Components
Defined in:
lib/mongoid/callbacks.rb

Overview

This module contains all the callback hooks for Mongoid.

Constant Summary collapse

CALLBACKS =
[
  :before_validation, :after_validation,
  :after_initialize,
  :before_create, :around_create, :after_create,
  :before_destroy, :around_destroy, :after_destroy,
  :before_save, :around_save, :after_save,
  :before_update, :around_update, :after_update,
]

Instance Method Summary collapse

Instance Method Details

#run_callbacks(kind, *args, &block) ⇒ Document

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

Examples:

Run the callbacks.

run_callbacks :save do
  save!
end

Parameters:

  • kind (Symbol)

    The type of callback to execute.

  • *args (Array)

    Any options.

Returns:

Since:

  • 2.3.0



40
41
42
43
44
# File 'lib/mongoid/callbacks.rb', line 40

def run_callbacks(kind, *args, &block)
  run_cascading_callbacks(cascadable_children(kind), kind, *args) do
    super(kind, *args, &block)
  end
end