module Sequel::Plugins::Paranoia
The paranoia plugin creates hooks that automatically set deleted timestamp fields. The field name used is configurable, and you can also set whether to overwrite existing deleted timestamps (false by default). Adapted from Timestamps plugin.
Usage:
# Soft deletion for all model instances using +deleted_at+ # (called before loading subclasses) Sequel::Model.plugin :paranoia # Paranoid Album instances, with custom column names Album.plugin :paranoia, :deleted_at=>:deleted_time # Paranoid Artist instances, forcing an overwrite of the deleted # timestamp Album.plugin :paranoia, :force=>true
Public Class Methods
configure(model, opts={})
click to toggle source
Configure the plugin by setting the avialable options. Note that if this method is run more than once, previous settings are ignored, and it will just use the settings given or the default settings. Options:
-
:deleted_at - The field to hold the deleted timestamp (default: :deleted_at)
-
:force - Whether to overwrite an existing deleted timestamp (default: false)
# File lib/sequel_paranoia.rb, line 28 def self.configure(model, opts={}) model.instance_eval do @deleted_timestamp_field = opts[:deleted_at]||:deleted_at @deleted_timestamp_overwrite = opts[:force]||false end model.class_eval do set_dataset filter("#{table_name}__#{@deleted_timestamp_field}".to_sym => nil) end end