Module: Paranoid::ParanoidMethods

Extended by:
ActiveSupport::Concern
Defined in:
lib/paranoid/paranoid_methods.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#destroyObject

Override the default destroy to allow us to soft delete records. This preserves the before_destroy and after_destroy callbacks. Because this is also called internally by Model.destroy_all and the Model.destroy(id), we don’t need to specify those methods separately.



54
55
56
57
58
59
60
61
# File 'lib/paranoid/paranoid_methods.rb', line 54

def destroy
  _run_destroy_callbacks do
    set_destroyed(field_destroyed.respond_to?(:call) ? field_destroyed.call : field_destroyed)
    @destroyed = true
  end

  self
end

#restoreObject

Restores the record



42
43
44
45
46
47
# File 'lib/paranoid/paranoid_methods.rb', line 42

def restore
  set_destroyed(field_not_destroyed.respond_to?(:call) ? field_not_destroyed.call : field_not_destroyed)
  @destroyed = false

  self
end