Class: Rushiro::AccessLevels

Inherits:
Object
  • Object
show all
Defined in:
lib/rushiro/access_levels.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ AccessLevels

Returns a new instance of AccessLevels.



4
5
6
7
8
# File 'lib/rushiro/access_levels.rb', line 4

def initialize(hash)
  @individual = Permissions.new(hash[:individual] || [])
  @organization = Permissions.new(hash[:organization] || [])
  @system = Permissions.new(hash[:system] || [])
end

Instance Attribute Details

#individualObject (readonly)

Returns the value of attribute individual.



3
4
5
# File 'lib/rushiro/access_levels.rb', line 3

def individual
  @individual
end

#musicglueObject (readonly)

Returns the value of attribute musicglue.



3
4
5
# File 'lib/rushiro/access_levels.rb', line 3

def musicglue
  @musicglue
end

#organizationObject (readonly)

Returns the value of attribute organization.



3
4
5
# File 'lib/rushiro/access_levels.rb', line 3

def organization
  @organization
end

Instance Method Details

#add_permission(perm) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rushiro/access_levels.rb', line 14

def add_permission(perm)
  level, rest = perm.split(GSEP, 2)
  case level
  when 'individual'
    @individual.add_permission(rest)
  when 'organization'
    @organization.add_permission(rest)
  when 'system'
    @system.add_permission(rest)
  else
    raise ArgumentError.new("Could not add permission for level: #{level} of #{level}#{SEP}#{perm}")
  end
end

#permitted?(perm) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/rushiro/access_levels.rb', line 10

def permitted?(perm)
  @system.permitted?(perm) || @organization.permitted?(perm) || @individual.permitted?(perm)
end

#remove_permission(perm) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rushiro/access_levels.rb', line 28

def remove_permission(perm)
  level, rest = perm.split(GSEP, 2)
  case level
  when 'individual'
    @individual.remove_permission(rest)
  when 'organization'
    @organization.remove_permission(rest)
  when 'system'
    @system.remove_permission(rest)
  else
    raise ArgumentError.new("Could not remove permission for level: #{level} of #{level}#{SEP}#{rest}")
  end
end

#serializeObject



41
42
43
# File 'lib/rushiro/access_levels.rb', line 41

def serialize
  Hash[:individual, @individual.serialize, :organization, @organization.serialize, :system, @system.serialize]
end