Class: AccessRoles::DetachedRoleSet
- Defined in:
- lib/access_roles/detached_role_set.rb
Overview
Wraps a set of Roles detached from a repository object
Instance Attribute Summary collapse
-
#role_set ⇒ Object
writeonly
Sets the attribute role_set.
Attributes inherited from RoleSet
Class Method Summary collapse
-
.deserialize(serialized) ⇒ Object
Deserialize a serialized RoleSet into a DetachedRoleSet.
-
.from_json(json) ⇒ Object
Deserialize a JSON representation of a set of Roles into a DetachedRoleSet.
Instance Method Summary collapse
- #grant(*roles) ⇒ Object
-
#initialize(role_set = Set.new) ⇒ DetachedRoleSet
constructor
A new instance of DetachedRoleSet.
-
#merge(other) ⇒ DetachedRoleSet
Merges the roles from another role set into the role set.
- #revoke(*roles) ⇒ Object
- #revoke_all ⇒ Object
- #to_a ⇒ Object
Methods inherited from RoleSet
#==, #granted?, #replace, #serialize, #to_json
Constructor Details
#initialize(role_set = Set.new) ⇒ DetachedRoleSet
Returns a new instance of DetachedRoleSet.
27 28 29 |
# File 'lib/access_roles/detached_role_set.rb', line 27 def initialize(role_set = Set.new) super role_set.to_set end |
Instance Attribute Details
#role_set=(value) ⇒ Object (writeonly)
Sets the attribute role_set
25 26 27 |
# File 'lib/access_roles/detached_role_set.rb', line 25 def role_set=(value) @role_set = value end |
Class Method Details
.deserialize(serialized) ⇒ Object
Deserialize a serialized RoleSet into a DetachedRoleSet
14 15 16 17 |
# File 'lib/access_roles/detached_role_set.rb', line 14 def deserialize(serialized) role_set = serialized.map { |role_data| Role.deserialize(role_data) } new(role_set) end |
.from_json(json) ⇒ Object
Deserialize a JSON representation of a set of Roles into a DetachedRoleSet
20 21 22 |
# File 'lib/access_roles/detached_role_set.rb', line 20 def from_json(json) deserialize JSON.parse(json) end |
Instance Method Details
#grant(*roles) ⇒ Object
31 32 33 |
# File 'lib/access_roles/detached_role_set.rb', line 31 def grant(*roles) role_set.merge coerce(roles) end |
#merge(other) ⇒ DetachedRoleSet
Merges the roles from another role set into the role set
50 51 52 53 |
# File 'lib/access_roles/detached_role_set.rb', line 50 def merge(other) role_set.merge other self end |
#revoke(*roles) ⇒ Object
35 36 37 |
# File 'lib/access_roles/detached_role_set.rb', line 35 def revoke(*roles) self.role_set -= coerce(roles) end |
#revoke_all ⇒ Object
39 40 41 |
# File 'lib/access_roles/detached_role_set.rb', line 39 def revoke_all clear end |
#to_a ⇒ Object
43 44 45 |
# File 'lib/access_roles/detached_role_set.rb', line 43 def to_a role_set.to_a end |