ProductPromotion
Logo

Ruby

made by https://0x3d.site

GitHub - JackDanger/permanent_records: Rails Plugin - soft-delete your ActiveRecord records. It's like an explicit version of ActsAsParanoid
Rails Plugin - soft-delete your ActiveRecord records. It's like an explicit version of ActsAsParanoid - JackDanger/permanent_records
Visit Site

GitHub - JackDanger/permanent_records: Rails Plugin - soft-delete your ActiveRecord records. It's like an explicit version of ActsAsParanoid

GitHub - JackDanger/permanent_records: 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 Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory