Class: Antigravity::Policy::Rule
- Inherits:
-
Object
- Object
- Antigravity::Policy::Rule
- Defined in:
- lib/antigravity/policy.rb
Overview
Rule — a single allow/deny/confirm entry in a policy.
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#tool_name ⇒ Object
readonly
Returns the value of attribute tool_name.
Instance Method Summary collapse
-
#initialize(action, tool_name = nil, condition: nil, handler: nil) ⇒ Rule
constructor
A new instance of Rule.
- #matches?(tool, args) ⇒ Boolean
-
#precedence ⇒ Object
Precedence order (higher = wins): 1.
Constructor Details
#initialize(action, tool_name = nil, condition: nil, handler: nil) ⇒ Rule
Returns a new instance of Rule.
41 42 43 44 45 46 |
# File 'lib/antigravity/policy.rb', line 41 def initialize(action, tool_name = nil, condition: nil, handler: nil) @action = action @tool_name = tool_name @condition = condition @handler = handler end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
39 40 41 |
# File 'lib/antigravity/policy.rb', line 39 def action @action end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
39 40 41 |
# File 'lib/antigravity/policy.rb', line 39 def condition @condition end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
39 40 41 |
# File 'lib/antigravity/policy.rb', line 39 def handler @handler end |
#tool_name ⇒ Object (readonly)
Returns the value of attribute tool_name.
39 40 41 |
# File 'lib/antigravity/policy.rb', line 39 def tool_name @tool_name end |
Instance Method Details
#matches?(tool, args) ⇒ Boolean
48 49 50 51 52 |
# File 'lib/antigravity/policy.rb', line 48 def matches?(tool, args) return false if @tool_name && @tool_name.to_sym != tool.to_sym return false if @condition && !@condition.call(name: tool, args: args) true end |
#precedence ⇒ Object
Precedence order (higher = wins):
- Tool specificity: Specific tool > Wildcard (nil)
- Condition specificity: Has predicate > No predicate
- Action restrictiveness: Deny > Confirm > Allow
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/antigravity/policy.rb', line 58 def precedence specificity = @tool_name ? 1 : 0 condition_score = @condition ? 1 : 0 action_score = case @action when :deny then 3 when :confirm then 2 when :allow then 1 else 0 end [specificity, condition_score, action_score] end |