Class: Ask::Agent::Policies::PermissionRules::Rule
- Inherits:
-
Data
- Object
- Data
- Ask::Agent::Policies::PermissionRules::Rule
- Defined in:
- lib/ask/agent/policies/permission_rules.rb
Overview
A single rule: tool pattern + optional argument pattern + decision.
Instance Attribute Summary collapse
-
#argument_pattern ⇒ Object
readonly
Returns the value of attribute argument_pattern.
-
#decision ⇒ Object
readonly
Returns the value of attribute decision.
-
#tool_pattern ⇒ Object
readonly
Returns the value of attribute tool_pattern.
Instance Method Summary collapse
- #argument_matches?(arguments) ⇒ Boolean
- #matches?(tool_name, arguments) ⇒ Boolean
- #tool_matches?(tool_name) ⇒ Boolean
- #universal? ⇒ Boolean
Instance Attribute Details
#argument_pattern ⇒ Object (readonly)
Returns the value of attribute argument_pattern
36 37 38 |
# File 'lib/ask/agent/policies/permission_rules.rb', line 36 def argument_pattern @argument_pattern end |
#decision ⇒ Object (readonly)
Returns the value of attribute decision
36 37 38 |
# File 'lib/ask/agent/policies/permission_rules.rb', line 36 def decision @decision end |
#tool_pattern ⇒ Object (readonly)
Returns the value of attribute tool_pattern
36 37 38 |
# File 'lib/ask/agent/policies/permission_rules.rb', line 36 def tool_pattern @tool_pattern end |
Instance Method Details
#argument_matches?(arguments) ⇒ Boolean
49 50 51 52 53 54 55 56 57 |
# File 'lib/ask/agent/policies/permission_rules.rb', line 49 def argument_matches?(arguments) return true if argument_pattern.nil? text = arguments.is_a?(Hash) ? JSON.generate(arguments) : arguments.to_s case argument_pattern when Regexp then argument_pattern.match?(text) else text.include?(argument_pattern.to_s) end end |
#matches?(tool_name, arguments) ⇒ Boolean
37 38 39 |
# File 'lib/ask/agent/policies/permission_rules.rb', line 37 def matches?(tool_name, arguments) tool_matches?(tool_name) && argument_matches?(arguments) end |
#tool_matches?(tool_name) ⇒ Boolean
41 42 43 44 45 46 47 |
# File 'lib/ask/agent/policies/permission_rules.rb', line 41 def tool_matches?(tool_name) case tool_pattern when :all then true when Regexp then tool_pattern.match?(tool_name.to_s) else tool_pattern.to_s == tool_name.to_s end end |
#universal? ⇒ Boolean
59 60 61 |
# File 'lib/ask/agent/policies/permission_rules.rb', line 59 def universal? argument_pattern.nil? end |