No release in over 3 years
Low commit activity in last 3 years
A monkey patch for ActiveRecord to prevent physical deletion.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 5, < 7.1
 Project Readme

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.