Class: Ingress::PermissionsRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/ingress/permissions_repository.rb

Defined Under Namespace

Modules: Hashes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePermissionsRepository

Returns a new instance of PermissionsRepository.



7
8
9
10
# File 'lib/ingress/permissions_repository.rb', line 7

def initialize
  @role_rules = Hashes.role_rules
  @role_subject_action_rule = Hashes.role_subject_action_rule
end

Instance Attribute Details

#role_rulesObject (readonly)

Returns the value of attribute role_rules.



5
6
7
# File 'lib/ingress/permissions_repository.rb', line 5

def role_rules
  @role_rules
end

Instance Method Details

#add_permission(role_identifier, allow, action, subject, conditions = nil) ⇒ Object



12
13
14
15
# File 'lib/ingress/permissions_repository.rb', line 12

def add_permission(role_identifier, allow, action, subject, conditions = nil)
  rule = PermissionRule.new(allows: allow, action: action, subject: subject, conditions: conditions)
  add_rule(role_identifier, rule)
end

#copy_to_role(role_identifier, permission_repository) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/ingress/permissions_repository.rb', line 37

def copy_to_role(role_identifier, permission_repository)
  permission_repository.role_rules.each_pair do |_, rules|
    rules.each do |rule|
      add_rule(role_identifier, rule)
    end
  end
  self
end

#merge(permission_repository) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/ingress/permissions_repository.rb', line 28

def merge(permission_repository)
  permission_repository.role_rules.each_pair do |role_identifier, rules|
    rules.each do |rule|
      add_rule(role_identifier, rule)
    end
  end
  self
end

#rules_for(role_identifier, action, subject) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/ingress/permissions_repository.rb', line 17

def rules_for(role_identifier, action, subject)
  rules = []

  rules += find_rules(role_identifier, action, subject)
  rules += find_rules(role_identifier, "*", "*")
  rules += find_rules(role_identifier, action, "*")
  rules += find_rules(role_identifier, "*", subject)

  rules
end