Skip to content

guard_against_physical_delete is monkey patch for ActiveRecord. This patch prevent deleting record physically.

License

Notifications You must be signed in to change notification settings

cookpad/guard_against_physical_delete

Repository files navigation

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.

About

guard_against_physical_delete is monkey patch for ActiveRecord. This patch prevent deleting record physically.

Resources

License

Stars

Watchers

Forks

Packages

No packages published