Module: MongoMapper::Callbacks

Defined in:
lib/mongomapper/callbacks.rb

Class Method Summary collapse

Instance Method Summary collapse

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_createObject



34
# File 'lib/mongomapper/callbacks.rb', line 34

def after_create() end

#after_destroyObject



81
# File 'lib/mongomapper/callbacks.rb', line 81

def after_destroy()  end

#after_saveObject



22
# File 'lib/mongomapper/callbacks.rb', line 22

def after_save()  end

#after_updateObject



45
# File 'lib/mongomapper/callbacks.rb', line 45

def after_update() end

#after_validationObject



57
# File 'lib/mongomapper/callbacks.rb', line 57

def after_validation() end

#after_validation_on_createObject



61
# File 'lib/mongomapper/callbacks.rb', line 61

def after_validation_on_create()  end

#after_validation_on_updateObject



65
# File 'lib/mongomapper/callbacks.rb', line 65

def after_validation_on_update()  end

#before_createObject



32
# File 'lib/mongomapper/callbacks.rb', line 32

def before_create() end

#before_destroyObject



79
# File 'lib/mongomapper/callbacks.rb', line 79

def before_destroy() end

#before_saveObject



20
# File 'lib/mongomapper/callbacks.rb', line 20

def before_save() end

#before_updateObject



43
# File 'lib/mongomapper/callbacks.rb', line 43

def before_update() end

#before_validationObject



55
# File 'lib/mongomapper/callbacks.rb', line 55

def before_validation() end

#before_validation_on_createObject



59
# File 'lib/mongomapper/callbacks.rb', line 59

def before_validation_on_create() end

#before_validation_on_updateObject



63
# File 'lib/mongomapper/callbacks.rb', line 63

def before_validation_on_update() end

#destroy_with_callbacksObject

: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:

Returns:



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