Module: OpenLoam::SoftDeletable

Extended by:
ActiveSupport::Concern
Defined in:
lib/open_loam/soft_deletable.rb

Overview

Soft-delete: destroying a business record hides it instead of erasing it. A recycle bin — for GDPR retention, for undo, for audits that still read cleanly after the fact. OpenLoam is "safe by default", so a soft-deleted record is EXCLUDED from every ordinary query; seeing it is something you opt INTO, never a filter you must remember to add.

equipment.soft_delete    # deleted_at = now; gone from Equipment.all
Equipment.with_deleted   # includes it — but STILL tenant-scoped
Equipment.only_deleted   # just the recycle bin
equipment.restore        # deleted_at = nil; back in every query
equipment.destroy        # the real erase — the row leaves the database

destroy still hard-deletes, for a genuine "forget me". The generated admin calls soft_delete, so its delete button is undoable; reach for destroy only when the row must actually leave the database.

Instance Method Summary collapse

Instance Method Details

#deleted? ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/open_loam/soft_deletable.rb', line 32

def deleted?
  deleted_at.present?
end

#restore ⇒ Object



44
45
46
# File 'lib/open_loam/soft_deletable.rb', line 44

def restore
  open_loam_toggle_deleted(deleted: false, bang: false)
end

#restore! ⇒ Object



48
49
50
# File 'lib/open_loam/soft_deletable.rb', line 48

def restore!
  open_loam_toggle_deleted(deleted: false, bang: true)
end

#soft_delete ⇒ Object



36
37
38
# File 'lib/open_loam/soft_deletable.rb', line 36

def soft_delete
  open_loam_toggle_deleted(deleted: true, bang: false)
end

#soft_delete! ⇒ Object



40
41
42
# File 'lib/open_loam/soft_deletable.rb', line 40

def soft_delete!
  open_loam_toggle_deleted(deleted: true, bang: true)
end