module Trasher

Constants

VERSION

Public Class Methods

deleted_at_column?(klass) click to toggle source
# File lib/trasher.rb, line 27
def self.deleted_at_column?(klass)
  klass.columns.map(&:name).include?('deleted_at')
end
deleted_by_column?(klass) click to toggle source
# File lib/trasher.rb, line 31
def self.deleted_by_column?(klass)
  klass.columns.map(&:name).include?('deleted_by_id')
end
included(base) click to toggle source
# File lib/trasher.rb, line 20
def self.included(base)
  unless base.ancestors.include?(ActiveRecord::Base)
    raise "You can only include this if #{base} extends ActiveRecord::Base"
  end
  base.extend(ClassMethods)
end

Public Instance Methods

recover!() click to toggle source
# File lib/trasher/trashable.rb, line 36
def recover!
  _trash(nil, nil)
end
trash!(trashed_by, trashed_at = nil) click to toggle source
# File lib/trasher/trashable.rb, line 29
def trash!(trashed_by, trashed_at = nil)
  raise TrashedWithoutTrashedBy unless trashed_by.present?

  trashed_at ||= DateTime.now
  _trash(trashed_at, trashed_by.try(:id))
end
trashed?() click to toggle source
# File lib/trasher/trashable.rb, line 25
def trashed?
  deleted_at.present?
end

Private Instance Methods

_trash(deleted_at, deleted_by_id) click to toggle source
# File lib/trasher/trashable.rb, line 42
def _trash(deleted_at, deleted_by_id)
  update_columns(deleted_at: deleted_at, deleted_by_id: deleted_by_id)
end