Commit c98ad454 by John Hawthorn

Use define_model_callbacks

parent ea0a0cee
...@@ -14,7 +14,6 @@ module Paranoia ...@@ -14,7 +14,6 @@ module Paranoia
def self.included(klazz) def self.included(klazz)
klazz.extend Query klazz.extend Query
klazz.extend Callbacks
end end
module Query module Query
...@@ -53,26 +52,6 @@ module Paranoia ...@@ -53,26 +52,6 @@ module Paranoia
end end
end end
module Callbacks
def self.extended(klazz)
[:restore, :real_destroy].each do |callback_name|
klazz.define_callbacks callback_name
klazz.define_singleton_method("before_#{callback_name}") do |*args, &block|
set_callback(callback_name, :before, *args, &block)
end
klazz.define_singleton_method("around_#{callback_name}") do |*args, &block|
set_callback(callback_name, :around, *args, &block)
end
klazz.define_singleton_method("after_#{callback_name}") do |*args, &block|
set_callback(callback_name, :after, *args, &block)
end
end
end
end
def destroy def destroy
transaction do transaction do
run_callbacks(:destroy) do run_callbacks(:destroy) do
...@@ -241,6 +220,8 @@ end ...@@ -241,6 +220,8 @@ end
ActiveSupport.on_load(:active_record) do ActiveSupport.on_load(:active_record) do
class ActiveRecord::Base class ActiveRecord::Base
def self.acts_as_paranoid(options={}) def self.acts_as_paranoid(options={})
define_model_callbacks :restore, :real_destroy
alias_method :really_destroyed?, :destroyed? alias_method :really_destroyed?, :destroyed?
alias_method :really_delete, :delete alias_method :really_delete, :delete
alias_method :destroy_without_paranoia, :destroy alias_method :destroy_without_paranoia, :destroy
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment