Skip to content

Commit

Permalink
Use paranoia_ aliases internally
Browse files Browse the repository at this point in the history
This makes paranoia's code itself more explicit.
  • Loading branch information
jhawthorn committed Nov 2, 2017
1 parent f6448c4 commit 87f8a0c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/paranoia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def paranoia_destroy
transaction do
run_callbacks(:destroy) do
@_disable_counter_cache = deleted?
result = delete
result = paranoia_delete
next result unless result && ActiveRecord::VERSION::STRING >= '4.2'
each_counter_cached_associations do |association|
foreign_key = association.reflection.foreign_key.to_sym
Expand Down Expand Up @@ -93,7 +93,7 @@ def restore!(opts = {})
# This only happened on Rails versions earlier than 4.1.
noop_if_frozen = ActiveRecord.version < Gem::Version.new("4.1")
if within_recovery_window?(recovery_window_range) && ((noop_if_frozen && !@attributes.frozen?) || !noop_if_frozen)
@_disable_counter_cache = !deleted?
@_disable_counter_cache = !paranoia_destroyed?
write_attribute paranoia_column, paranoia_sentinel_value
update_columns(paranoia_restore_attributes)
each_counter_cached_associations do |association|
Expand Down Expand Up @@ -130,7 +130,7 @@ def paranoia_destroyed?
def really_destroy!
transaction do
run_callbacks(:real_destroy) do
@_disable_counter_cache = deleted?
@_disable_counter_cache = paranoia_destroyed?
dependent_reflections = self.class.reflections.select do |name, reflection|
reflection.options[:dependent] == :destroy
end
Expand Down Expand Up @@ -300,7 +300,7 @@ class UniquenessValidator < ActiveModel::EachValidator
class AssociationNotSoftDestroyedValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
# if association is soft destroyed, add an error
if value.present? && value.deleted?
if value.present? && value.paranoia_destroyed?
record.errors[attribute] << 'has been soft-deleted'
end
end
Expand Down

0 comments on commit 87f8a0c

Please sign in to comment.