Class: Checken::UserProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/checken/user_proxy.rb

Overview

The user proxy class sits on top of a user and provides the methods that checken needs. You can write your own proxy or use the default. If you use the default you’ll need to make sure that the users you provide implement the methods this proxy will call.

All interactions between checken and a user will happen via a proxy. This default class is a useful benchmark list of how your user should behave.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ UserProxy

Returns a new instance of UserProxy.

Parameters:

  • user (Object)


14
15
16
# File 'lib/checken/user_proxy.rb', line 14

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject

Returns the value of attribute user.



11
12
13
# File 'lib/checken/user_proxy.rb', line 11

def user
  @user
end

Instance Method Details

#contextsArray<Symbol>

An array of contexts that this user is part of

Returns:

  • (Array<Symbol>)


40
41
42
43
44
45
46
# File 'lib/checken/user_proxy.rb', line 40

def contexts
  if @user.respond_to?(:checken_contexts)
    @user.checken_contexts
  else
    []
  end
end

#descriptionString

Return a suitable description for this user for use in log files

Returns:

  • (String)


21
22
23
24
25
26
27
# File 'lib/checken/user_proxy.rb', line 21

def description
  if @user.respond_to?(:id)
    "#{@user.class}##{@user.id}"
  else
    "#{@user.class}"
  end
end

#granted_permissionsArray<String>

Returns an array of permissions that this user has permission to use.

Returns:

  • (Array<String>)


33
34
35
# File 'lib/checken/user_proxy.rb', line 33

def granted_permissions
  @user.assigned_checken_permissions
end