Commit b262c5bd by John Hawthorn

Fix really_destroy! for ruby 2.3

For some reason in ruby 2.3 this definition was interpreted as private.
There was no reason to be defining it where it was, so I've moved it
into the paranoia module.
parent 7a617a42
...@@ -125,6 +125,30 @@ module Paranoia ...@@ -125,6 +125,30 @@ module Paranoia
end end
alias :deleted? :paranoia_destroyed? alias :deleted? :paranoia_destroyed?
def really_destroy!
transaction do
run_callbacks(:real_destroy) do
dependent_reflections = self.class.reflections.select do |name, reflection|
reflection.options[:dependent] == :destroy
end
if dependent_reflections.any?
dependent_reflections.each do |name, reflection|
association_data = self.send(name)
# has_one association can return nil
# .paranoid? will work for both instances and classes
next unless association_data && association_data.paranoid?
if reflection.collection?
next association_data.with_deleted.each(&:really_destroy!)
end
association_data.really_destroy!
end
end
write_attribute(paranoia_column, current_time_from_proper_timezone)
destroy_without_paranoia
end
end
end
private private
def paranoia_restore_attributes def paranoia_restore_attributes
...@@ -185,31 +209,7 @@ class ActiveRecord::Base ...@@ -185,31 +209,7 @@ class ActiveRecord::Base
def self.acts_as_paranoid(options={}) def self.acts_as_paranoid(options={})
alias :really_destroyed? :destroyed? alias :really_destroyed? :destroyed?
alias :really_delete :delete alias :really_delete :delete
alias :destroy_without_paranoia :destroy alias :destroy_without_paranoia :destroy
def really_destroy!
transaction do
run_callbacks(:real_destroy) do
dependent_reflections = self.class.reflections.select do |name, reflection|
reflection.options[:dependent] == :destroy
end
if dependent_reflections.any?
dependent_reflections.each do |name, reflection|
association_data = self.send(name)
# has_one association can return nil
# .paranoid? will work for both instances and classes
next unless association_data && association_data.paranoid?
if reflection.collection?
next association_data.with_deleted.each(&:really_destroy!)
end
association_data.really_destroy!
end
end
write_attribute(paranoia_column, current_time_from_proper_timezone)
destroy_without_paranoia
end
end
end
include Paranoia include Paranoia
class_attribute :paranoia_column, :paranoia_sentinel_value class_attribute :paranoia_column, :paranoia_sentinel_value
......
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