Module: MongoMapper::Plugins::Callbacks

Defined in:
lib/novelys_mongo_mapper/plugins/callbacks.rb

Defined Under Namespace

Modules: InstanceMethods

Constant Summary collapse

METHODS =
["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"]

Class Method Summary collapse

Class Method Details

.configure(model) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/novelys_mongo_mapper/plugins/callbacks.rb', line 12

def self.configure(model)
  model.class_eval do
    include ActiveSupport::Callbacks

    define_callbacks *METHODS
    
    # If Rails 3, support the new callback syntax
    if metaclass.method_defined?(:set_callback)
      METHODS.each do |method|
        class_eval <<-"end_eval", __FILE__, __LINE__
          def self.#{method}(*methods, &block)
            set_callback :#{method}, *methods, &block
          end
        end_eval
      end
    end
  end
end