Skip to content

7even/mark_as_deleted

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mark_as_deleted Build Status

mark_as_deleted is a small gem which simplifies adding 'marked as deleted' functionality to your models.

Installation

gem install mark_as_deleted

in your console, or

gem 'mark_as_deleted'

in your Gemfile.

Usage

Simply add a deleted boolean column to your model table and call mark_as_deleted in that model definition, and you are ready to go.

class Post < ActiveRecord::Base
  mark_as_deleted
end

Now the Post#destroy method won't erase the record from the database, it will update the deleted column to true instead.

If you want to give the column another name, you should just pass that name to the mark_as_deleted call, like so:

class Post < ActiveRecord::Base
  mark_as_deleted :is_deleted
end

Of course you must have a column by that name in your table.

Roadmap

  1. ActiveRecord scopes based on deleted column
  2. Maybe a generator creating a migration and adding mark_as_deleted to the model
  3. Maybe other ORMs support

Contributing

Fork the repository, push your changes to a topic branch and send me a pull request.

About

Allows to mark AR objects as deleted instead of actual deletion

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages