lib/couch_potato/persistence/callbacks.rb in langalex-couch_potato-0.1 vs lib/couch_potato/persistence/callbacks.rb in langalex-couch_potato-0.1.1

- old
+ new

@@ -3,10 +3,11 @@ module Callbacks def self.included(base) base.extend ClassMethods base.class_eval do + attr_accessor :skip_callbacks def self.callbacks @@callbacks ||= {} @@callbacks[self.name] ||= {:before_validation_on_create => [], :before_validation_on_update => [], :before_validation_on_save => [], :before_create => [], :after_create => [], :before_update => [], :after_update => [], @@ -14,12 +15,20 @@ :before_destroy => [], :after_destroy => []} end end end + def save_without_callbacks + self.skip_callbacks = true + result = save + self.skip_callbacks = false + result + end + private def run_callbacks(name) + return if skip_callbacks self.class.callbacks[name].each do |callback| self.send callback end end \ No newline at end of file