0.05
No commit activity in last 3 years
No release in over 3 years
kakurenbo-puti provides an ActiveRecord-friendly soft-delete gem. This gem does not override methods of ActiveRecord. I think that kakurenbo-puti is cho-iketeru! (very cool!)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 0.7.8
~> 10.0
~> 3.0.0
~> 1.3.10
~> 0.8.7.6

Runtime

>= 4.1.0
 Project Readme

Kakurenbo-Puti

kakurenbo-puti provides an ActiveRecord-friendly soft-delete gem. This gem does not override methods of ActiveRecord.

I think that kakurenbo-puti is cho-iketeru! (very cool!)

Build Status Coverage Status Code Climate

Installation

Add this line to your application's Gemfile:

gem 'kakurenbo-puti'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kakurenbo-puti

Usage

At first, add soft_destroyed_at column to your model.

$ rails g migration AddSoftDestroyedAtToYourModel soft_destroyed_at:datetime:index
$ rake db:migrate

Next, call soft_deletable in model.

class Member < ActiveRecord::Base
  soft_deletable
end

Scopes

# Get models without soft-deleted
Model.without_soft_destroyed

# Get models only soft-deleted
Model.only_soft_destroyed

Soft-delete record

model.soft_destroy

# or
model.soft_destroy!

# check soft_destroyed
model.soft_destroyed? # => true

Restore record

model.restore

# or
model.restore!

Advanced

Definition of the dependency

Use dependent_associations option of soft-deletable. This option is useable only in belongs_to.

class Parent < ActiveRecord::Base
  soft_deletable
  has_many :children
end

class Child < ActiveRecord::Base
  soft_deletable dependent_associations: [:parent]
  belongs_to :parent
end

# create instance
parent = Parent.create!
child  = Child.create!

# add child
parent.children << child

child.soft_destroyed? # false

# soft-destroy parent
parent.soft_destroy

child.soft_destroyed? # true

Change column of datetime of soft-delete.

class Member < ActiveRecord::Base
  soft_deletable :column => :deleted_at
end

License

This gem is released under the MIT license.