Skip to content

ichi/soft_deletable_petit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SoftDeletablePetit

Based on kakurenbo-puti.

Installation

Add this line to your application's Gemfile:

gem 'soft_deletable_petit'

And then execute:

$ bundle

Or install it yourself as:

$ gem install soft_deletable_petit

Usage

Add deleted_at column to your model.

and

class YourModel < ActiveRecord::Base
  soft_deletable
end

Methods

m.destroy_softly # or destroy_softly!
m.deleted? # => true

m.restore # or m.restore!
m.living? # => true

Scopes

YourModel.living
YourModel.deleted

Configuration

In model

class YourModel < ActiveRecord::Base
  soft_deletable \
    column:                     :deleted_at,
    soft_delete_method_name:    :destroy_softly,
    restore_method_name:        :restore,
    soft_deleted_scope:         :deleted,
    without_soft_deleted_scope: :living
end

and you can change default configuration with SoftDeletablePetit.configure.

# config/initializers/soft_deletable_petit.rb
SoftDeletablePetit.configure do |config|
  config.column                     = :deleted_at
  config.soft_delete_method_name    = :destroy_softly
  config.restore_method_name        = :restore
  config.soft_deleted_scope         = :deleted
  config.without_soft_deleted_scope = :living
end

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published