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

Inherits:
Object
  • Object
show all
Extended by:
Deprecation
Includes:
Models::Validatable
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Validatable

included, #validator

Constructor Details

#initialize(*args) ⇒ Role

Returns a new instance of Role.



35
36
37
38
# File 'lib/ddr/auth/roles/role.rb', line 35

def initialize(*args)
  super
  validate!
end

Class Method Details

.build(*args) ⇒ Object



25
26
27
28
# File 'lib/ddr/auth/roles/role.rb', line 25

def build(*args)
  Deprecation.warn(Role, "`build` is deprecated; use `new` instead.")
  new(*args)
end

.from_json(json) ⇒ Object



30
31
32
# File 'lib/ddr/auth/roles/role.rb', line 30

def from_json(json)
  new JSON.parse(json)
end

Instance Method Details

#in_policy_scope?Boolean

Returns:

  • (Boolean)


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

def in_policy_scope?
  scope == Roles::POLICY_SCOPE
end

#in_resource_scope?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/ddr/auth/roles/role.rb', line 54

def in_resource_scope?
  scope == Roles::RESOURCE_SCOPE
end

#permissionsArray<Symbol>

Returns the permissions associated with the role

Returns:

  • (Array<Symbol>)

    the permissions



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

def permissions
  Roles.type_map[role_type].permissions
end

#to_jsonObject



44
45
46
# File 'lib/ddr/auth/roles/role.rb', line 44

def to_json
  JSON.dump(to_h)
end

#to_sObject



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

def to_s
  to_h.to_s
end

#validate!Object



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

def validate!
  if invalid?
    raise Ddr::Models::Error, "Invalid Role: #{errors.full_messages.join('; ')}"
  end
end