Git Product home page Git Product logo

kakurenbo's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.