Class: Ddr::Auth::Roles::Role
- Inherits:
-
ActiveTriples::Resource
- Object
- ActiveTriples::Resource
- Ddr::Auth::Roles::Role
- Includes:
- Hydra::Validations
- 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
-
.build(args = {}) ⇒ Role
(also: deserialize)
Build a Role instance from hash attributes.
-
.from_json(json) ⇒ Role
Deserialize a Role from JSON.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Roles are considered equivalent (== and eql?) if they are of the same type and have the same agent and scope.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #in_policy_scope? ⇒ Boolean
- #in_resource_scope? ⇒ Boolean
- #inspect ⇒ Object
-
#permissions ⇒ Array<Symbol>
Returns the permissions associated with the role.
- #to_h ⇒ Object (also: #to_hash, #serialize)
- #to_s ⇒ Object
Class Method Details
.build(args = {}) ⇒ Role Also known as: deserialize
Build a Role instance from hash attributes
29 30 31 32 33 34 35 36 |
# File 'lib/ddr/auth/roles/role.rb', line 29 def build(args={}) new.tap do |role| role.attributes = build_attributes(args) if role.invalid? raise Ddr::Models::Error, "Invalid #{self.name}: #{role.errors..join('; ')}" end end end |
.from_json(json) ⇒ Role
Deserialize a Role from JSON
43 44 45 |
# File 'lib/ddr/auth/roles/role.rb', line 43 def from_json(json) deserialize JSON.parse(json) end |
Instance Method Details
#==(other) ⇒ Boolean
Roles are considered equivalent (== and eql?) if they are of the same type and have the same agent and scope.
69 70 71 72 73 74 75 |
# File 'lib/ddr/auth/roles/role.rb', line 69 def ==(other) if self.class == other.class self.to_h == other.to_h else super end end |
#eql?(other) ⇒ Boolean
77 78 79 |
# File 'lib/ddr/auth/roles/role.rb', line 77 def eql?(other) (self == other) && (hash == other.hash) end |
#hash ⇒ Object
81 82 83 |
# File 'lib/ddr/auth/roles/role.rb', line 81 def hash to_h.hash end |
#in_policy_scope? ⇒ Boolean
93 94 95 |
# File 'lib/ddr/auth/roles/role.rb', line 93 def in_policy_scope? scope.first == Roles::POLICY_SCOPE end |
#in_resource_scope? ⇒ Boolean
89 90 91 |
# File 'lib/ddr/auth/roles/role.rb', line 89 def in_resource_scope? scope.first == Roles::RESOURCE_SCOPE end |
#inspect ⇒ Object
97 98 99 100 |
# File 'lib/ddr/auth/roles/role.rb', line 97 def inspect "#<#{self.class.name} role_type=#{role_type.first.inspect}, " \ "agent=#{agent.first.inspect}, scope=#{scope.first.inspect}>" end |
#permissions ⇒ Array<Symbol>
Returns the permissions associated with the role
110 111 112 |
# File 'lib/ddr/auth/roles/role.rb', line 110 def Roles.type_map[role_type.first]. end |
#to_h ⇒ Object Also known as: to_hash, serialize
102 103 104 |
# File 'lib/ddr/auth/roles/role.rb', line 102 def to_h as_json end |
#to_s ⇒ Object
85 86 87 |
# File 'lib/ddr/auth/roles/role.rb', line 85 def to_s to_h.to_s end |