Sha256: 549e81d59df702ca32592514cbd1d489dee1f7d5879ced4650c57a9942ee38f3

Contents?: true

Size: 894 Bytes

Versions: 16

Compression:

Stored size: 894 Bytes

Contents

require 'active_support/concern'
require 'active_model/callbacks'

module CouchPotato
  module Persistence
    module Callbacks
      def self.included(base) #:nodoc:
        base.extend ActiveModel::Callbacks

        base.class_eval do
          attr_accessor :skip_callbacks

          define_model_callbacks :create, :save, :update, :destroy
          define_model_callbacks *[:save, :create, :update].map {|c| :"validation_on_#{c}"}
          define_model_callbacks :validation unless Config.validation_framework == :active_model
        end
      end

      # Runs all callbacks on a model with the given name, e.g. :after_create.
      # 
      # This method is called by the CouchPotato::Database object when saving/destroying an object 
      def run_callbacks(name, &block)
        return if skip_callbacks

        send(:"_run_#{name}_callbacks", &block)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
couch_potato-0.6.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-0.5.7 lib/couch_potato/persistence/callbacks.rb
couch_potato-rails2-0.5.8 lib/couch_potato/persistence/callbacks.rb
couch_potato-rails2-0.5.7 lib/couch_potato/persistence/callbacks.rb
couch_potato-rails2-0.5.6 lib/couch_potato/persistence/callbacks.rb
couch_potato-0.5.6 lib/couch_potato/persistence/callbacks.rb
couch_potato-0.5.5 lib/couch_potato/persistence/callbacks.rb
couch_potato-0.5.4 lib/couch_potato/persistence/callbacks.rb
couch_potato-0.5.3 lib/couch_potato/persistence/callbacks.rb
couch_potato-0.5.2 lib/couch_potato/persistence/callbacks.rb
couch_potato-0.5.1 lib/couch_potato/persistence/callbacks.rb
couch_potato-0.5.0 lib/couch_potato/persistence/callbacks.rb
davber_couch_potato-0.4.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-0.4.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-0.3.2 lib/couch_potato/persistence/callbacks.rb
couch_potato-0.3.1 lib/couch_potato/persistence/callbacks.rb