Module: MongoMapper::Callbacks
- Defined in:
- lib/mongomapper/callbacks.rb
Class Method Summary collapse
-
.included(model) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #after_create ⇒ Object
- #after_destroy ⇒ Object
- #after_save ⇒ Object
- #after_update ⇒ Object
- #after_validation ⇒ Object
- #after_validation_on_create ⇒ Object
- #after_validation_on_update ⇒ Object
- #before_create ⇒ Object
- #before_destroy ⇒ Object
- #before_save ⇒ Object
- #before_update ⇒ Object
- #before_validation ⇒ Object
- #before_validation_on_create ⇒ Object
- #before_validation_on_update ⇒ Object
-
#destroy_with_callbacks ⇒ Object
:nodoc:.
-
#valid_with_callbacks? ⇒ Boolean
:nodoc:.
Class Method Details
.included(model) ⇒ Object
:nodoc:
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mongomapper/callbacks.rb', line 3 def self.included(model) #:nodoc: model.class_eval do extend Observable include ActiveSupport::Callbacks define_callbacks *%w( 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 ) [:create_or_update, :valid?, :create, :update, :destroy].each do |method| alias_method_chain method, :callbacks end end end |
Instance Method Details
#after_create ⇒ Object
34 |
# File 'lib/mongomapper/callbacks.rb', line 34 def after_create() end |
#after_destroy ⇒ Object
81 |
# File 'lib/mongomapper/callbacks.rb', line 81 def after_destroy() end |
#after_save ⇒ Object
22 |
# File 'lib/mongomapper/callbacks.rb', line 22 def after_save() end |
#after_update ⇒ Object
45 |
# File 'lib/mongomapper/callbacks.rb', line 45 def after_update() end |
#after_validation ⇒ Object
57 |
# File 'lib/mongomapper/callbacks.rb', line 57 def after_validation() end |
#after_validation_on_create ⇒ Object
61 |
# File 'lib/mongomapper/callbacks.rb', line 61 def after_validation_on_create() end |
#after_validation_on_update ⇒ Object
65 |
# File 'lib/mongomapper/callbacks.rb', line 65 def after_validation_on_update() end |
#before_create ⇒ Object
32 |
# File 'lib/mongomapper/callbacks.rb', line 32 def before_create() end |
#before_destroy ⇒ Object
79 |
# File 'lib/mongomapper/callbacks.rb', line 79 def before_destroy() end |
#before_save ⇒ Object
20 |
# File 'lib/mongomapper/callbacks.rb', line 20 def before_save() end |
#before_update ⇒ Object
43 |
# File 'lib/mongomapper/callbacks.rb', line 43 def before_update() end |
#before_validation ⇒ Object
55 |
# File 'lib/mongomapper/callbacks.rb', line 55 def before_validation() end |
#before_validation_on_create ⇒ Object
59 |
# File 'lib/mongomapper/callbacks.rb', line 59 def before_validation_on_create() end |
#before_validation_on_update ⇒ Object
63 |
# File 'lib/mongomapper/callbacks.rb', line 63 def before_validation_on_update() end |
#destroy_with_callbacks ⇒ Object
:nodoc:
82 83 84 85 86 87 |
# File 'lib/mongomapper/callbacks.rb', line 82 def destroy_with_callbacks #:nodoc: return false if callback(:before_destroy) == false result = destroy_without_callbacks callback(:after_destroy) result end |
#valid_with_callbacks? ⇒ Boolean
:nodoc:
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mongomapper/callbacks.rb', line 67 def valid_with_callbacks? #:nodoc: return false if callback(:before_validation) == false result = new? ? callback(:before_validation_on_create) : callback(:before_validation_on_update) return false if false == result result = valid_without_callbacks? callback(:after_validation) new? ? callback(:after_validation_on_create) : callback(:after_validation_on_update) return result end |