module EffectiveTrash

bundle exec rails generate effective_trash:trash_archived_booleans

Constants

VERSION

Public Class Methods

authorize!(controller, action, resource) click to toggle source
# File lib/effective_trash.rb, line 31
def self.authorize!(controller, action, resource)
  raise Effective::AccessDenied unless authorized?(controller, action, resource)
end
authorized?(controller, action, resource) click to toggle source
# File lib/effective_trash.rb, line 18
def self.authorized?(controller, action, resource)
  @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact

  return !!authorization_method unless authorization_method.respond_to?(:call)
  controller = controller.controller if controller.respond_to?(:controller)

  begin
    !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
  rescue *@_exceptions
    false
  end
end
current_user() click to toggle source
# File lib/effective_trash.rb, line 40
def self.current_user
  @effective_trash_current_user
end
current_user=(user) click to toggle source

This is set by the “set_effective_trash_current_user” before_filter.

# File lib/effective_trash.rb, line 36
def self.current_user=(user)
  @effective_trash_current_user = user
end
setup() { |self| ... } click to toggle source
# File lib/effective_trash.rb, line 14
def self.setup
  yield self
end
trash!(obj) click to toggle source

Trash it - Does not delete the original object. This is run in a before_destroy, or through a script.

# File lib/effective_trash.rb, line 46
def self.trash!(obj)
  args = (obj.respond_to?(:acts_as_trashable_options) ? obj.acts_as_trashable_options : {})

  trash = Effective::Trash.new(
    trashed: obj,
    user: EffectiveTrash.current_user,
    trashed_to_s: obj.to_s,
    trashed_extra: (trashed_extra if obj.respond_to?(:trashed_extra)),
    details: Effective::Resource.new(obj).instance_attributes(args)
  ).save!
end