kakurenbo-puti provides an ActiveRecord-friendly soft-delete gem. This gem does not override methods of ActiveRecord.
Switch branches/tags
Clone or download
Latest commit afe97fd Dec 24, 2017
Permalink
Failed to load latest commit information.
lib Support Ruby2.4 and Rails5 Jun 30, 2017
spec support rails 5 Sep 17, 2016
vendor Add vendor/.keep Jun 30, 2017
.coveralls.yml fix travis-ci Feb 1, 2015
.gitignore Fix deep nest relation problem. Jun 14, 2015
.travis.yml Support Ruby2.4 and Rails5 Jun 30, 2017
Gemfile fix travis-ci Feb 1, 2015
LICENSE.txt FirstCommit Jan 31, 2015
README.md Fix README.md Dec 19, 2016
Rakefile FirstCommit Jan 31, 2015
kakurenbo-puti.gemspec Update yard Dec 24, 2017

README.md

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.