Project

softie

0.0
No commit activity in last 3 years
No release in over 3 years
Softie adds soft-delete functionality to MongoMapper documents with minimal fuss
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0
~> 2.11

Runtime

>= 0.9.0
 Project Readme

Softie

Build Status Code Climate

Softie has troubles letting go. It is a plugin for MongoMapper, and lets records be soft-deleted easily.

It contains the bare minimum that I use at the moment. Softie does not add a default scope, but it does add a scope (configurable). Softie does not override #destroy, #delete and other methods.

The app this was extracted from stores which User deleted the record in deleted_by. This feature is disabled by default, but can easily be enabled, and the field name and class configured.

Installation

Add this line to your application's Gemfile:

gem 'softie'

Or install it yourself as:

$ gem install softie

Configuration

Either load it into all models, or individual models:

# add to all models
MongoMapper::Document.plugin Softie

# add to a specific model
class Item
  include MongoMapper::Document
  plugin Softie
end

Then call softie to configure it

softie [options]

The supported options are as follows:

  • key: Symbol. Defaults to :deleted_at
  • scope: Symbol. Defaults to :active. Set to a falsy value to disable.
  • deleted_by_field: Symbol. Defaults to :deleted_by
  • deleted_by_class: Class. Defaults to nil. Set to a class to enable this functionality.

Usage

Call deleted! on your document. This sets deleted_at to Time.now.utc and saves the document. If you are tracking who deleted it, pass it as deleted!(by: current_user).

To restore a document, call restore!.

If you want to handle saving manually, use deleted and restore.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request