Module: MongoMapper::Callbacks
- Defined in:
- lib/mongo_mapper/callbacks.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(model) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mongo_mapper/callbacks.rb', line 3 def self.included(model) model.class_eval do include ActiveSupport::Callbacks define_callbacks( :before_save, :after_save, :before_create, :after_create, :before_update, :after_update, :before_validation, :after_validation, :before_validation_on_create, :after_validation_on_create, :before_validation_on_update, :after_validation_on_update, :before_destroy, :after_destroy ) end end |
Instance Method Details
#destroy ⇒ Object
31 32 33 34 35 36 |
# File 'lib/mongo_mapper/callbacks.rb', line 31 def destroy run_callbacks(:before_destroy) result = super run_callbacks(:after_destroy) result end |
#valid? ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mongo_mapper/callbacks.rb', line 19 def valid? action = new? ? 'create' : 'update' run_callbacks(:before_validation) run_callbacks("before_validation_on_#{action}".to_sym) result = super run_callbacks("after_validation_on_#{action}".to_sym) run_callbacks(:after_validation) result end |