module Paranoia
Constants
- VERSION
Public Class Methods
included(klazz)
click to toggle source
# File lib/paranoia.rb, line 2 def self.included(klazz) klazz.extend Query klazz.extend Callbacks end
Public Instance Methods
delete()
click to toggle source
# File lib/paranoia.rb, line 64 def delete return if new_record? touch_paranoia_column(false) end
destroy()
click to toggle source
# File lib/paranoia.rb, line 50 def destroy run_callbacks(:destroy) { touch_paranoia_column(true) } end
destroy!()
click to toggle source
Calls superclass method
# File lib/paranoia.rb, line 59 def destroy! destroyed? ? super : destroy || raise(ActiveRecord::RecordNotDestroyed) end
destroyed?()
click to toggle source
# File lib/paranoia.rb, line 79 def destroyed? !!send(paranoia_column) end
Also aliased as: deleted?
restore!(opts = {})
click to toggle source
# File lib/paranoia.rb, line 69 def restore!(opts = {}) ActiveRecord::Base.transaction do run_callbacks(:restore) do update_column paranoia_column, nil restore_associated_records if opts[:recursive] end end end
Also aliased as: restore
Private Instance Methods
restore_associated_records()
click to toggle source
restore associated records that have been soft deleted when we called destroy
# File lib/paranoia.rb, line 99 def restore_associated_records destroyed_associations = self.class.reflect_on_all_associations.select do |association| association.options[:dependent] == :destroy end destroyed_associations.each do |association| association = send(association.name) if association.paranoid? association.only_deleted.each { |record| record.restore(:recursive => true) } end end end
touch_paranoia_column(with_transaction=false)
click to toggle source
touch paranoia column. insert time to paranoia column. @param with_transaction [Boolean] exec with ActiveRecord Transactions.
# File lib/paranoia.rb, line 89 def touch_paranoia_column(with_transaction=false) if with_transaction with_transaction_returning_status { touch(paranoia_column) } else touch(paranoia_column) end end