Commit c98ad454 by John Hawthorn

Use define_model_callbacks

parent ea0a0cee
......@@ -14,7 +14,6 @@ module Paranoia
def self.included(klazz)
klazz.extend Query
klazz.extend Callbacks
end
module Query
......@@ -53,26 +52,6 @@ module Paranoia
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
transaction do
run_callbacks(:destroy) do
......@@ -241,6 +220,8 @@ end
ActiveSupport.on_load(:active_record) do
class ActiveRecord::Base
def self.acts_as_paranoid(options={})
define_model_callbacks :restore, :real_destroy
alias_method :really_destroyed?, :destroyed?
alias_method :really_delete, :delete
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