Class: AccessRoles::Role
- Inherits:
-
ActiveTriples::Resource
- Object
- ActiveTriples::Resource
- AccessRoles::Role
- Includes:
- Hydra::Validations
- Defined in:
- lib/access_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
30 31 32 33 34 35 36 37 |
# File 'lib/access_roles/role.rb', line 30 def build(args={}) new.tap do |role| role.attributes = build_attributes(args) if role.invalid? raise "Invalid #{self.name}: #{role.errors..join('; ')}" end end end |
.from_json(json) ⇒ Role
Deserialize a Role from JSON
44 45 46 |
# File 'lib/access_roles/role.rb', line 44 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.
70 71 72 73 74 75 76 |
# File 'lib/access_roles/role.rb', line 70 def ==(other) if self.class == other.class self.to_h == other.to_h else super end end |
#eql?(other) ⇒ Boolean
78 79 80 |
# File 'lib/access_roles/role.rb', line 78 def eql?(other) (self == other) && (hash == other.hash) end |
#hash ⇒ Object
82 83 84 |
# File 'lib/access_roles/role.rb', line 82 def hash to_h.hash end |
#in_policy_scope? ⇒ Boolean
94 95 96 |
# File 'lib/access_roles/role.rb', line 94 def in_policy_scope? scope.first == Roles::POLICY_SCOPE end |
#in_resource_scope? ⇒ Boolean
90 91 92 |
# File 'lib/access_roles/role.rb', line 90 def in_resource_scope? scope.first == Roles::RESOURCE_SCOPE end |
#inspect ⇒ Object
98 99 100 101 |
# File 'lib/access_roles/role.rb', line 98 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
114 115 116 |
# File 'lib/access_roles/role.rb', line 114 def Roles.type_map[role_type.first]. end |
#to_h ⇒ Object Also known as: to_hash, serialize
103 104 105 106 107 108 |
# File 'lib/access_roles/role.rb', line 103 def to_h { "role_type"=>role_type, "agent"=>agent, "scope"=>scope, } end |
#to_s ⇒ Object
86 87 88 |
# File 'lib/access_roles/role.rb', line 86 def to_s to_h.to_s end |