Class: AccessRoles::DetachedRoleSet

Inherits:
RoleSet
  • Object
show all
Defined in:
lib/access_roles/detached_role_set.rb

Overview

Wraps a set of Roles detached from a repository object

Instance Attribute Summary collapse

Attributes inherited from RoleSet

#role_set

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RoleSet

#==, #granted?, #replace, #serialize, #to_json

Constructor Details

#initialize(role_set = Set.new) ⇒ 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_allObject


39
40
41
# File 'lib/access_roles/detached_role_set.rb', line 39

def revoke_all
  clear
end

#to_aObject


43
44
45
# File 'lib/access_roles/detached_role_set.rb', line 43

def to_a
  role_set.to_a
end