Class: Legion::Rbac::Permission

Inherits:
Object
  • Object
show all
Includes:
Logging::Helper
Defined in:
lib/legion/rbac/permission.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_pattern:, actions:) ⇒ Permission

Returns a new instance of Permission.



12
13
14
15
16
# File 'lib/legion/rbac/permission.rb', line 12

def initialize(resource_pattern:, actions:)
  @resource_pattern = resource_pattern
  @actions = actions.map(&:to_s)
  @resource_regex = self.class.send(:pattern_to_regex, resource_pattern)
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



10
11
12
# File 'lib/legion/rbac/permission.rb', line 10

def actions
  @actions
end

#resource_patternObject (readonly)

Returns the value of attribute resource_pattern.



10
11
12
# File 'lib/legion/rbac/permission.rb', line 10

def resource_pattern
  @resource_pattern
end

Instance Method Details

#matches?(resource, action) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/legion/rbac/permission.rb', line 18

def matches?(resource, action)
  matched = pattern_matches?(resource) && action_matches?(action)
  log.debug("RBAC permission matched pattern=#{resource_pattern} action=#{action} resource=#{resource}") if matched
  matched
end