Class: Ddr::Auth::Roles::DetachedRoleSet

Inherits:
RoleSet
  • Object
show all
Defined in:
lib/ddr/auth/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, #granted?, #replace, #serialize, #to_json

Constructor Details

#initialize(role_set = Set.new) ⇒ DetachedRoleSet

Returns a new instance of DetachedRoleSet.



28
29
30
# File 'lib/ddr/auth/roles/detached_role_set.rb', line 28

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

Parameters:

  • value

    the value to set the attribute role_set to.



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

def role_set=(value)
  @role_set = value
end

Class Method Details

.deserialize(serialized) ⇒ Object

Deserialize a serialized RoleSet into a DetachedRoleSet



15
16
17
18
# File 'lib/ddr/auth/roles/detached_role_set.rb', line 15

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



21
22
23
# File 'lib/ddr/auth/roles/detached_role_set.rb', line 21

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

Instance Method Details

#grant(*roles) ⇒ Object



32
33
34
# File 'lib/ddr/auth/roles/detached_role_set.rb', line 32

def grant(*roles)
  role_set.merge coerce(roles)
end

#merge(other) ⇒ DetachedRoleSet

Merges the roles from another role set into the role set

Parameters:

  • other (Enumerable<Role>)

Returns:



51
52
53
54
# File 'lib/ddr/auth/roles/detached_role_set.rb', line 51

def merge(other)
  role_set.merge other
  self
end

#revoke(*roles) ⇒ Object



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

def revoke(*roles)
  self.role_set -= coerce(roles)
end

#revoke_allObject



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

def revoke_all
  clear
end

#to_aObject



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

def to_a
  role_set.to_a
end