Created
January 14, 2010 15:03
-
-
Save kevinvaldek/277226 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/mongo_mapper/plugins/callbacks.rb | |
module MongoMapper | |
module Plugins | |
module Callbacks | |
module InstanceMethods | |
def self.included(model) | |
model.class_eval do | |
extend ActiveModel::Callbacks | |
define_model_callbacks( | |
:save, | |
:create, | |
:update, | |
:validation, | |
:validation_on_create, | |
:validation_on_update, | |
:destroy | |
) | |
end | |
end | |
def valid? | |
_run_validation_callbacks do | |
send(:"_run_validation_on_#{new? ? 'create' : 'update'}_callbacks") do | |
super | |
end | |
end | |
end | |
def destroy | |
_run_destroy_callbacks { super } | |
end | |
private | |
def create_or_update(*args) | |
_run_save_callbacks { super } | |
end | |
def create(*args) | |
_run_create_callbacks { super } | |
end | |
def update(*args) | |
_run_update_callbacks { super } | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment