Module: EffectiveTrash

Defined in:
lib/generators/effective_trash/trash_archived_booleans_generator.rb,
lib/effective_trash.rb,
lib/effective_trash/engine.rb,
lib/effective_trash/version.rb,
lib/effective_trash/set_current_user.rb,
lib/generators/effective_trash/install_generator.rb

Overview

bundle exec rails generate effective_trash:trash_archived_booleans

Defined Under Namespace

Modules: Generators, SetCurrentUser Classes: Engine

Constant Summary collapse

VERSION =
'0.2.2'.freeze

Class Method Summary collapse

Class Method Details

.authorized?(controller, action, resource) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'lib/effective_trash.rb', line 19

def self.authorized?(controller, action, resource)
  if authorization_method.respond_to?(:call) || authorization_method.kind_of?(Symbol)
    raise Effective::AccessDenied.new() unless (controller || self).instance_exec(controller, action, resource, &authorization_method)
  end
  true
end

.current_userObject



31
32
33
# File 'lib/effective_trash.rb', line 31

def self.current_user
  @effective_trash_current_user
end

.current_user=(user) ⇒ Object

This is set by the “set_effective_trash_current_user” before_filter.



27
28
29
# File 'lib/effective_trash.rb', line 27

def self.current_user=(user)
  @effective_trash_current_user = user
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



15
16
17
# File 'lib/effective_trash.rb', line 15

def self.setup
  yield self
end

.trash!(obj) ⇒ Object

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



37
38
39
40
41
42
43
44
45
# File 'lib/effective_trash.rb', line 37

def self.trash!(obj)
  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
  ).save!
end