Class: Ddr::Auth::Roles::Role

Inherits:
Valkyrie::Resource
  • Object
show all
Defined in:
lib/ddr/auth/roles/role.rb

Overview

The assignment of a role to an agent within a scope.

Constant Summary collapse

DEFAULT_SCOPE =
Roles::RESOURCE_SCOPE
ValidScope =
Valkyrie::Types::Coercible::String.default(DEFAULT_SCOPE).enum(*(Roles::SCOPES))
ValidRoleType =
Valkyrie::Types::Strict::String.enum(*(Roles.titles))
ValidAgent =
Valkyrie::Types::Coercible::String.constrained(min_size: 1)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(args = {}) ⇒ Object

DEPRECATED: Use constructor



40
41
42
# File 'lib/ddr/auth/roles/role.rb', line 40

def self.build(args={})
  new(args)
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Roles are considered equal (==) if they are of the same type and have the same agent and scope.

Parameters:

  • other (Object)

    the object of comparison

Returns:

  • (Boolean)

    the result



48
49
50
51
52
53
# File 'lib/ddr/auth/roles/role.rb', line 48

def ==(other)
  self.class == other.class &&
    role_type == other.role_type &&
    scope == other.scope &&
    agent == other.agent
end

#in_policy_scope?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/ddr/auth/roles/role.rb', line 61

def in_policy_scope?
  scope == Roles::POLICY_SCOPE
end

#in_resource_scope?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/ddr/auth/roles/role.rb', line 57

def in_resource_scope?
  scope == Roles::RESOURCE_SCOPE
end

#inspectObject



65
66
67
68
# File 'lib/ddr/auth/roles/role.rb', line 65

def inspect
  "#<#{self.class.name} role_type=#{role_type.inspect}, " \
  "agent=#{agent.inspect}, scope=#{scope.inspect}>"
end

#permissionsArray<Symbol>

Returns the permissions associated with the role

Returns:

  • (Array<Symbol>)

    the permissions



72
73
74
# File 'lib/ddr/auth/roles/role.rb', line 72

def permissions
  Roles.type_map[role_type].permissions
end