Sha256: f59f80b1c9b398d1b6a92738a6c3f41ccb938a2bc0a8c1b85fdd8cb177c9daea

Contents?: true

Size: 797 Bytes

Versions: 28

Compression:

Stored size: 797 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}"}
        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

28 entries across 28 versions & 1 rubygems

Version Path
couch_potato-1.17.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.16.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.15.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.14.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.13.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.12.1 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.12.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.11.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.10.1 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.10.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.9.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.7.1 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.7.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.6.5 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.6.4 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.6.3 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.4.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.3.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.2.0 lib/couch_potato/persistence/callbacks.rb
couch_potato-1.1.4 lib/couch_potato/persistence/callbacks.rb