Module: Mongoid::Callbacks
Overview
This module contains all the callback hooks for Mongoid.
Constant Summary collapse
- CALLBACKS =
[ :before_validation, :after_validation, :after_initialize, :after_build, :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
-
#callback_executable?(kind) ⇒ true, false
Is the provided type of callback executable by this document?.
-
#run_callbacks(kind, *args, &block) ⇒ Document
Run the callbacks for the document.
Instance Method Details
#callback_executable?(kind) ⇒ true, false
Is the provided type of callback executable by this document?
document.callback_executable?(:save)
36 37 38 |
# File 'lib/mongoid/callbacks.rb', line 36 def callback_executable?(kind) respond_to?("_#{kind}_callbacks") end |
#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.
55 56 57 58 59 60 61 62 |
# File 'lib/mongoid/callbacks.rb', line 55 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 |