Class: Legion::Rbac::Permission
- Inherits:
-
Object
- Object
- Legion::Rbac::Permission
- Includes:
- Logging::Helper
- Defined in:
- lib/legion/rbac/permission.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#resource_pattern ⇒ Object
readonly
Returns the value of attribute resource_pattern.
Instance Method Summary collapse
-
#initialize(resource_pattern:, actions:) ⇒ Permission
constructor
A new instance of Permission.
- #matches?(resource, action) ⇒ Boolean
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
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
10 11 12 |
# File 'lib/legion/rbac/permission.rb', line 10 def actions @actions end |
#resource_pattern ⇒ Object (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
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 |