Giter VIP home page Giter VIP logo

kakurenbo-puti's Introduction

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.

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.