https://github.com/mshahzadtariq/persistable
Persist sensitive data by enabling soft delete functionality
https://github.com/mshahzadtariq/persistable
gem persistence ruby ruby-on-rails
Last synced: 4 months ago
JSON representation
Persist sensitive data by enabling soft delete functionality
- Host: GitHub
- URL: https://github.com/mshahzadtariq/persistable
- Owner: mshahzadtariq
- License: mit
- Created: 2015-06-01T10:15:25.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2018-09-27T07:04:31.000Z (almost 8 years ago)
- Last Synced: 2025-10-11T20:20:55.005Z (9 months ago)
- Topics: gem, persistence, ruby, ruby-on-rails
- Language: Ruby
- Size: 32.2 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: MIT-LICENSE
Awesome Lists containing this project
README
#### Persist Deleted Records for Mongoid
===============
Soft delete functionality for Mongoid ORM so you may recover records at later stage.
#### Installation
=======
Add following line to your Gemfile
gem 'persistable'
or
gem 'persistable', git: 'https://github.com/mshahzadtariq/persistable'
or
gem install persistable
Then generate persistable on your sensitive model at which you need to activate soft delete functionality to preserve data
rails generate persistable:migration table_name
i.e.
rails generate persistable:migration :estimates
This will generate migration file and automatically include Persistable module to the model for which you want to enable soft delete and recovery feature
class MyModel
include Mongoid::Document
include Mongoid::Persistable
......
end
and that is all.
#### Usage
=======
Persist sensitive data with options to recover data.
To persist record, call destroy method on object. It will not delete record from database but persist that so you can recover it in the future if required.
object.destroy
It also has two scopes
only_deleted: Fetch only deleted records of that particular model
e.g
Model.only_deleted
with_deleted: Fetch all records of that particular model including deleted records
e.g
Model.with_deleted
To recover records, call recover method on object
Model.only_deleted.first.recover
To permanently delete record from system/database, call delete method
object.delete