Module: MongoMapper::Plugins::Callbacks::InstanceMethods
- Defined in:
- lib/mongo_mapper/plugins/callbacks.rb
Instance Method Summary collapse
- #destroy ⇒ Object
- #run_callbacks(kind, options = {}, &block) ⇒ Object
- #valid? ⇒ Boolean
-
#valid_for_group?(group) ⇒ Boolean
Overriding validatable’s valid_for_group? to integrate validation callbacks.
Instance Method Details
#destroy ⇒ Object
73 74 75 76 77 78 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 73 def destroy run_callbacks(:before_destroy) result = super run_callbacks(:after_destroy) result end |
#run_callbacks(kind, options = {}, &block) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 80 def run_callbacks(kind, ={}, &block) callback_chain_method = "#{kind}_callback_chain" return unless self.class.respond_to?(callback_chain_method) self.class.send(callback_chain_method).run(self, , &block) self..each do |association| if association.one? self.send(association.name).run_callbacks(kind, , &block) else self.send(association.name).each do |document| document.run_callbacks(kind, , &block) end end end end |
#valid? ⇒ Boolean
52 53 54 55 56 57 58 59 60 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 52 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 |
#valid_for_group?(group) ⇒ Boolean
Overriding validatable’s valid_for_group? to integrate validation callbacks
63 64 65 66 67 68 69 70 71 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 63 def valid_for_group?(group) #:nodoc: errors.clear run_before_validations run_callbacks(:validate) new? ? run_callbacks(:validate_on_create) : run_callbacks(:validate_on_update) self.class.validate_children(self, group) self.validate_group(group) errors.empty? end |