def define_callbacks(klass)
      observer = self
      observer_name = observer.class.name.underscore.gsub('/', '__')
      Mongoid::Interceptable.observables.each do |callback|
        next unless respond_to?(callback)
        callback_meth = :"_notify_#{observer_name}_for_#{callback}"
        unless klass.respond_to?(callback_meth)
          klass.send(:define_method, callback_meth) do |&block|
            if value = observer.update(callback, self, &block)
              value
            else
              block.call if block
            end
          end
          klass.send(callback, callback_meth)
        end
      end
      self
    end
def define_callbacks(klass)
      observer = self
      observer_name = observer.class.name.underscore.gsub('/', '__')
      Mongoid::Interceptable.observables.each do |callback|
        next unless respond_to?(callback)
        callback_meth = :"_notify_#{observer_name}_for_#{callback}"
        unless klass.respond_to?(callback_meth)
          klass.send(:define_method, callback_meth) do |&block|
            if value = observer.update(callback, self, &block)
              value
            else
              block.call if block
            end
          end
          klass.send(callback, callback_meth)
        end
      end
      self
    end
Defines all the callbacks for each observer of the model.

 @example Define all the callbacks.
   observer.define_callbacks(Document)

 @param [ Class ] klass The model to define them on.