Module: Mongoid::Callbacks
Overview
This module contains all the callback hooks for Mongoid.
Constant Summary collapse
- CALLBACKS =
[ :after_build, :after_create, :after_destroy, :after_initialize, :after_save, :after_update, :after_upsert, :after_validation, :around_create, :around_destroy, :around_save, :around_update, :around_upsert, :before_create, :before_destroy, :before_save, :before_update, :before_upsert, :before_validation ]
Instance Method Summary collapse
-
#run_after_callbacks(*kinds) ⇒ Object
Run only the after callbacks for the specific event.
-
#run_before_callbacks(*kinds) ⇒ Object
Run only the before callbacks for the specific event.
-
#run_callbacks(kind, *args, &block) ⇒ Document
Run the callbacks for the document.
Instance Method Details
#run_after_callbacks(*kinds) ⇒ Object
Note:
ActiveSupport does not allow this type of behaviour by default, so Mongoid has to get around it and implement itself.
Run only the after callbacks for the specific event.
52 53 54 55 56 |
# File 'lib/mongoid/callbacks.rb', line 52 def run_after_callbacks(*kinds) kinds.each do |kind| run_targeted_callbacks(:after, kind) end end |
#run_before_callbacks(*kinds) ⇒ Object
Note:
ActiveSupport does not allow this type of behaviour by default, so Mongoid has to get around it and implement itself.
Run only the before callbacks for the specific event.
71 72 73 74 75 |
# File 'lib/mongoid/callbacks.rb', line 71 def run_before_callbacks(*kinds) kinds.each do |kind| run_targeted_callbacks(:before, kind) end 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.
92 93 94 95 96 97 98 99 |
# File 'lib/mongoid/callbacks.rb', line 92 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 super(kind, *args, &block) end |