Class: Rushiro::AccessControlHash

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

Direct Known Subclasses

AllowBasedControl, DenyBasedControl

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ AccessControlHash

Returns a new instance of AccessControlHash.



6
7
8
9
10
11
# File 'lib/rushiro/access_control_hash.rb', line 6

def initialize(hash)
  @allows = AccessLevels.new(hash[:allows] || {})
  @denies = AccessLevels.new(hash[:denies] || {})
  @dirty = false
  @original = hash
end

Instance Attribute Details

#allowsObject (readonly)

Returns the value of attribute allows.



5
6
7
# File 'lib/rushiro/access_control_hash.rb', line 5

def allows
  @allows
end

#deniesObject (readonly)

Returns the value of attribute denies.



5
6
7
# File 'lib/rushiro/access_control_hash.rb', line 5

def denies
  @denies
end

#dirtyObject (readonly)

Returns the value of attribute dirty.



5
6
7
# File 'lib/rushiro/access_control_hash.rb', line 5

def dirty
  @dirty
end

#originalObject (readonly)

Returns the value of attribute original.



5
6
7
# File 'lib/rushiro/access_control_hash.rb', line 5

def original
  @original
end

Instance Method Details

#add_permission(perm) ⇒ Object

as string “allow|individual|domain(|action(|instance))”



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rushiro/access_control_hash.rb', line 17

def add_permission(perm) #as string "allow|individual|domain(|action(|instance))"
  grant, rest = perm.split(GSEP, 2)
  case grant
  when 'allows'
    @allows.add_permission(rest) and @dirty = true
  when 'denies'
    @denies.add_permission(rest) and @dirty = true
  else
    raise ArgumentError.new("Could not add permission for type: #{grant} of #{perm}")
  end
end

#permitted?(perm) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rushiro/access_control_hash.rb', line 13

def permitted?(perm)
  # virtual
end

#remove_permission(perm) ⇒ Object

as string “allow|individual|domain(|action(|instance))”



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

def remove_permission(perm) #as string "allow|individual|domain(|action(|instance))"
  grant, rest = perm.split(GSEP, 2)
  case grant
  when 'allows'
    @allows.remove_permission(rest) and @dirty = true
  when 'denies'
    @denies.remove_permission(rest) and @dirty = true
  else
    raise ArgumentError.new("Could not remove permission for type: #{grant} of #{perm}")
  end
end

#serializeObject



41
42
43
44
45
46
47
# File 'lib/rushiro/access_control_hash.rb', line 41

def serialize
  unless @dirty
    @original
  else
    Hash[:allows, @allows.serialize, :denies, @denies.serialize]
  end
end