Skip to content

alfa-jpn/kakurenbo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kakurenbo

Kakurenbo provides soft delete. Kakurenbo is a re-implementation of paranoia and acts_as_paranoid for Rails4. implemented a function that other gems are not enough.

The usage of the Kakurenbo is very very very simple. Only add deleted_at(datetime) to column. Of course you can use acts_as_paranoid.In addition, Kakurenbo has many advantageous.

Warning

kakurenbo is deprecated if you use in a new rails project!

You should use kakurenbo-puti!

Installation

gem 'kakurenbo'

Usage

You need only to add 'deleted_at' to model.

rails generate migration AddDeletedAtToModels deleted_at:datetime

The model having deleted_at becomes able to soft-delete automatically.

Kakurenbo provides acts_as_paranoid method for compatibility.

Basic Example

soft-delete

# if action is cancelled by callbacks, return false.
model.destroy

# if action is cancelled by callbacks, raise ActiveRecord::RecordNotDestroyed.
model.destroy!

# selected model will be destroyed.
Model.where(:foo => 'bar').destroy_all

when want without callbacks.

model.delete

# selected model will be deleted.
Model.where(:foo => 'bar').delete_all

restore a record

# if action is cancelled by callbacks, return false.
model.restore

# if action is cancelled by callbacks, raise ActiveRecord::RecordNotRestored.
model.restore!

When restore, call restore callbacks.before_restore after_restore

hard-delete

Use hard option.

model.destroy(hard: true)

# without callbacks.
model.delete(hard: true)

# selected model will be destroyed.
Model.where(:foo => 'bar').destroy_all(nil, hard: true)

# selected model will be destroyed.
Model.where(:foo => 'bar').delete_all(nil, hard: true)

check if a record is fotdeleted

model.destroyed?

find with soft-deleted

Model.with_deleted

find only the soft-deleted

Model.only_deleted

License

This gem is released under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages