Class: Ingress::PermissionRule

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allows:, action:, subject:, conditions: nil) ⇒ PermissionRule

Returns a new instance of PermissionRule.



5
6
7
8
9
10
# File 'lib/ingress/permission_rule.rb', line 5

def initialize(allows:, action:, subject:, conditions: nil)
  @allows = allows
  @action = action
  @subject = subject
  @conditions = [conditions].compact.flatten
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



3
4
5
# File 'lib/ingress/permission_rule.rb', line 3

def action
  @action
end

#conditionsObject (readonly)

Returns the value of attribute conditions.



3
4
5
# File 'lib/ingress/permission_rule.rb', line 3

def conditions
  @conditions
end

#subjectObject (readonly)

Returns the value of attribute subject.



3
4
5
# File 'lib/ingress/permission_rule.rb', line 3

def subject
  @subject
end

Instance Method Details

#allows?Boolean

Returns:

  • (Boolean)


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

def allows?
  @allows
end

#match?(given_action, given_subject, user) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/ingress/permission_rule.rb', line 16

def match?(given_action, given_subject, user)
  return false unless action_matches?(given_action)
  return false unless subject_matches?(given_subject)

  conditions_match?(user, given_subject)
end