• Stars
    star
    268
  • Rank 147,605 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 16 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rails Plugin - soft-delete your ActiveRecord records. It's like an explicit version of ActsAsParanoid

PermanentRecords

http://github.com/JackDanger/permanent_records/

This gem prevents any of your ActiveRecord data from being destroyed. Any model that you've given a "deleted_at" datetime column will have that column set rather than let the record be deleted.

What methods does it give me?

User.find(3).destroy          # Sets the 'deleted_at' attribute to Time.now
                              # and returns a frozen record. If halted by a
                              # before_destroy callback it returns false instead

User.find(3).destroy(:force)  # Executes the real destroy method, the record
                              # will be removed from the database.

User.destroy_all              # Soft-deletes all User records.

User.delete_all               # bye bye everything (no soft-deleting here)

There are also two scopes provided for easily searching deleted and not deleted records:

User.deleted.find(...)        # Only returns deleted records.

User.not_deleted.find(...)    # Only returns non-deleted records.

Note: Your normal finds will, by default, include deleted records. You'll have to manually use the not_deleted scope to avoid this:

User.find(1)                  # Will find record number 1, even if it's deleted.

User.not_deleted.find(1)      # This is probably what you want, it doesn't find deleted records.

Can I easily undelete records?

Yes. All you need to do is call the 'revive' method.

User.find(3).destroy         # The user is now deleted.

User.find(3).revive          # The user is back to it's original state.

And if you had dependent records that were set to be destroyed along with the parent record:

class User < ActiveRecord::Base
  has_many :comments, :dependent => :destroy
end

User.find(3).destroy         # All the comments are destroyed as well.

User.find(3).revive          # All the comments that were just destroyed
                             # are now back in pristine condition.

Forcing deletion works the same way: if you hard delete a record, its dependent records will also be hard deleted.

Can I use default scopes?

default_scope where(:deleted_at => nil)

If you use such a default scope, you will need to simulate the deleted scope with a method

def self.deleted
  self.unscoped.where('deleted_at IS NOT NULL')
end

Is Everything Automated?

Yes. You don't have to change ANY of your code to get permanent archiving of all your data with this gem. When you call destroy on any record (or destroy_all on a class or association) your records will all have a deleted_at timestamp set on them.

Upgrading from 3.x

The behaviour of the destroy method has been updated so that it now returns false when halted by a before_destroy callback. This is in line with behaviour of ActiveRecord. For more information see #47.

Productionizing

If you operate a system where destroying or reviving a record takes more than about 3 seconds then you'll want to customize PermanentRecords.dependent_record_window = 10.seconds or some other value that works for you.

Patches welcome, forks celebrated.

Copyright 2015 Jack Danger Canty @ https://jdanger.com released under the MIT license

More Repositories

1

wave

Ruby client for Google Wave
Ruby
82
star
2

collectlinks

Golang package to read href tags from an HTML page
Go
69
star
3

alphadecimal

Base62 encoding and decoding to turn numbers into very compact strings
Ruby
58
star
4

jack

Javascript Rack Adapter
JavaScript
41
star
5

gocrawler

Practicing building a web crawler in golang
Go
38
star
6

immutable_attributes

specify attributes within an ActiveRecord model that can be set but not modified
Ruby
24
star
7

dotfiles

Jack Danger's ridiculously optimized terminal
Shell
23
star
8

simple_memoize

Ultra lightweight gem/plugin to do in-memory caching of any Ruby method
Ruby
23
star
9

geoip_server

Query the MaxMind GeoIP data records via a self-hosted web service
Ruby
21
star
10

hsql

Store a hash of data with your SQL queries
Ruby
21
star
11

apple_store

Instant dev environment on any Mac
Shell
19
star
12

twilio_contactable

Automatically confirm your user's phone numbers via voice or sms
Ruby
17
star
13

chromiumos

Google's ChromiumOS synced hourly from official server
C
15
star
14

shawty-server

super-lightweight url-shortener designed to run FAST on Heroku.com
Ruby
14
star
15

marked

Quick ruby debugging, done right
Ruby
13
star
16

jquery-ui

Updated hourly from the jQuery-UI SVN repo
JavaScript
13
star
17

hacker_news

An example of a stand-alone Ruby web filter
Ruby
12
star
18

sweet_assets

Rails Plugin - a Ruby way to manage your stylesheets and javascripts. Don't put all your assets in your layout; define what you need where you need them.
Ruby
11
star
19

inline_styles

Apply CSS styles from a stylesheet directly into element attributes
Ruby
9
star
20

eight-puzzle

Ruby
9
star
21

cached_values

Rails Plugin - memoize and store to the db a record attribute generated by any expression or SQL query.
Ruby
9
star
22

pragprog_erlang_exercises

Hands-on work from the Joe Armstrong Erlang book
Erlang
8
star
23

iCalReader

Javascript parser for the iCal format
JavaScript
8
star
24

pdfservice

A rack app for converting HTML to PDF via a HTTP call
Ruby
8
star
25

silk_icon_sprite

A single image sprite of all FamFamFam Silk Icons, with Ruby helper
Ruby
7
star
26

parenscript

ParenScript is a small Lispy language that can be compiled to JavaScript. [updated hourly]
Common Lisp
7
star
27

human_codes

Convert integers to short, human-scannable alphanumeric strings (skipping 'l', '1', 'o', '0', etc.) and back.
Ruby
7
star
28

feminizer

Programmatically swap the gender of an English text string
HTML
7
star
29

erlang_socket

Socket.erl - a wrapper for handling tcp and ssl connections in erlang
Erlang
6
star
30

maze

Stack-based Ruby maze generator
Ruby
6
star
31

simple_pages

Rails Plugin - a RailsEngines-based CMS extension for any Rails project
Ruby
6
star
32

yelp

GitHub clone of yelp gem from RubyForge
Ruby
6
star
33

http101

Course materials for HTTP 101
Ruby
6
star
34

jspec_red_green

A port of the RedGreen gem to use with JSpec and Johnson
JavaScript
5
star
35

object_proxy

ObjectProxy provides a proxied interface to Ruby objects. It lets you add methods to objects that don't normally support them.
Ruby
5
star
36

txter

Drop-in SMS support for any Ruby app
Ruby
4
star
37

jackdanger.github.com

Jack Danger's GitHub Page
Ruby
4
star
38

barcodeservice

A Sinatra app serving barcodes from simple urls
Ruby
4
star
39

smita-lightbox

Example of a super-simple photography site
JavaScript
4
star
40

google-wave-robot-python-client

Google Way Robot Python Client written by Google's David Byttow [update hourly]
Python
4
star
41

binarytweet

The absurd conclusion of internet publishing
JavaScript
3
star
42

ruby_prototype

Provides Ruby1.9 with a method prototyping interface
Ruby
3
star
43

wells_fargo

Ruby Client for the Wells Fargo Payment Manager
Ruby
3
star
44

google-wave-samples

Git clone of the Google Wave Sample projects [updated hourly]
Java
3
star
45

bike-europe

Interview Question
Java
3
star
46

image_monkey

Ruby
3
star
47

jackcanty.com-in-scheme

Homepage
Scheme
3
star
48

syntaxhighlighter

Javascript-only syntax highlighting by Alex Gorbatchev
3
star
49

loxate

Loฯ‡ate: email-based universal location service
Ruby
3
star
50

arduino_tutorials

My first few steps with Arduino
Java
3
star
51

phonetics

C
2
star
52

nerdboard

You can touch type. Repurpose your keyboard.
2
star
53

managercode

Your team knows your product, you know your team
Ruby
2
star
54

thesaurus_rex

Objects in mirror are more redundant than they appear
JavaScript
2
star
55

traffic

JavaScript
2
star
56

cljintro

a place for me to play with Clojure project structure
Clojure
2
star
57

programming_collective_intelligence

Working through the examples in "Programming Collective Intelligence" by Toby Segaran
Python
2
star
58

ruby101

Intro to Ruby webserver development
Ruby
2
star
59

google-wave-robot-java-client

The official Google Wave Java client [updated from svn hourly]
Java
2
star
60

gnightphone

G'night phone - text how the day went then put the phone away
Python
2
star
61

centurion

Listen to your code when it hollers at you.
JavaScript
2
star
62

jquery-geocodable

Javascript geocoding of text field input
2
star
63

google_url_signatures

Sign a url with your Google key, useful for Places API and Maps V3 API
Ruby
2
star
64

love_icon_field

Icon Field - a small 2d gameboard written in Lร–VE with love
Lua
2
star
65

barcoder

Barcode image generation library, for non-write filesystems.
Ruby
2
star
66

shawty-client

A tiny Ruby client for accessing a Shawty server
Ruby
2
star
67

erlang-mysql-driver

Revamped MySQL driver for Erlang
Erlang
2
star
68

without_accents

Convert certain unicode/8-bit characters into their simplified visual counterparts
Ruby
2
star
69

love

Lร–VE - the unquestionably awesome 2D game engine in Lua (updated hourly from SVN)
C
2
star
70

software-in-production

The draft of a book on running software in production
1
star
71

terraform-module-gsuite-route53

Terraform module for route53 GSuite records
HCL
1
star
72

ruby_internal_api

Extract parts of your monolith by creating internal APIs for your Ruby code
Ruby
1
star
73

eallydumb

This is ubygems
Ruby
1
star
74

popefact

Ruby
1
star
75

empirical

EmpiricalApp.com
JavaScript
1
star
76

synecdoche

Shell
1
star
77

dfa

Determinate Finite Automaton
Ruby
1
star
78

yosemite

Find available trailheads in Yosemite National Park
Ruby
1
star
79

apprunway

Enhance any rack-capable application to run on Google's App Engine
Ruby
1
star
80

processingjs-square-logo

Java
1
star
81

artofwomanliness

what's good for the gander...
Ruby
1
star
82

shawty-server-scala

A port of the Shawty url-shortner to Scala
Scala
1
star
83

reverse_pony

Objective-C
1
star
84

under_construction

one point twenty-one jigga-whatts
JavaScript
1
star
85

postgres-replication-example

Shell
1
star
86

getdangerous

A backup of the ridiculous website made by Tien Nguyen
HTML
1
star
87

letsgocamping

A complete list of official U.S. recreation sites
Ruby
1
star
88

amazon_presentation

JavaScript
1
star
89

silent_voices

Illustrating the symbolic annihilation of women in the bible.
HTML
1
star
90

monorailer

utilities for working with huge Rails apps
Ruby
1
star
91

joining-the-tech-industry

This is a collaborative guidebook for folks joining the tech industry to help know how to be safe and supported. Create a pull request or write to [email protected] to make changes.
1
star
92

seattleliquor

Navigable pricebook for Washington State liquor prices
Ruby
1
star