Skip to content

Latest commit

 

History

History
52 lines (35 loc) · 1.27 KB

README.md

File metadata and controls

52 lines (35 loc) · 1.27 KB

guard_against_physical_delete

test

Gem Version

A monkey patch for ActiveRecord to prevent physical deletion.

Installation

Add this line to your Rails application's Gemfile:

gem 'guard_against_physical_delete'

And then execute:

bundle install

Usage

If there is a record with a column named deleted_at, an exception is automatically raised on the methods that are likely to perform physical deletion.

# This will raise `GuardAgainstPhysicalDelete::PhysicalDeleteError`.
user.delete

# To allow phsycal deletion, do it in `physical_delete { ... }` block.
user.class.physical_delete do
  user.delete
end

Configuration

If you want to use a column name other than deleted_at, you can change it as follows:

class User < ApplicationRecord
  self.logical_delete_column = :removed_at
end

License

This gem is available as open source under the terms of the MIT License. See License.txt for more details.