Class: SwarmSDK::Hooks::Definition
- Inherits:
-
Object
- Object
- SwarmSDK::Hooks::Definition
- Defined in:
- lib/swarm_sdk/hooks/definition.rb
Overview
Represents a single hook configuration
A hook definition includes:
- Event type (when to trigger)
- Optional matcher (regex for tool names)
- Priority (execution order)
- Proc to execute
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#proc ⇒ Object
readonly
Returns the value of attribute proc.
Instance Method Summary collapse
-
#initialize(event:, matcher: nil, priority: 0, proc:) ⇒ Definition
constructor
A new instance of Definition.
-
#matches?(tool_name) ⇒ Boolean
Check if this hook should execute for a given tool name.
-
#named_hook? ⇒ Boolean
Check if this hook uses a named reference.
-
#resolve_proc(registry) ⇒ Proc
Resolve the actual proc, looking up named hooks if needed.
Constructor Details
#initialize(event:, matcher: nil, priority: 0, proc:) ⇒ Definition
Returns a new instance of Definition.
27 28 29 30 31 32 |
# File 'lib/swarm_sdk/hooks/definition.rb', line 27 def initialize(event:, matcher: nil, priority: 0, proc:) @event = event @matcher = compile_matcher(matcher) @priority = priority @proc = proc end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
21 22 23 |
# File 'lib/swarm_sdk/hooks/definition.rb', line 21 def event @event end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
21 22 23 |
# File 'lib/swarm_sdk/hooks/definition.rb', line 21 def matcher @matcher end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
21 22 23 |
# File 'lib/swarm_sdk/hooks/definition.rb', line 21 def priority @priority end |
#proc ⇒ Object (readonly)
Returns the value of attribute proc.
21 22 23 |
# File 'lib/swarm_sdk/hooks/definition.rb', line 21 def proc @proc end |
Instance Method Details
#matches?(tool_name) ⇒ Boolean
Check if this hook should execute for a given tool name
38 39 40 41 42 |
# File 'lib/swarm_sdk/hooks/definition.rb', line 38 def matches?(tool_name) return true if @matcher.nil? # No matcher = matches everything @matcher.match?(tool_name) end |
#named_hook? ⇒ Boolean
Check if this hook uses a named reference
47 48 49 |
# File 'lib/swarm_sdk/hooks/definition.rb', line 47 def named_hook? @proc.is_a?(Symbol) end |
#resolve_proc(registry) ⇒ Proc
Resolve the actual proc, looking up named hooks if needed
56 57 58 59 60 61 62 63 |
# File 'lib/swarm_sdk/hooks/definition.rb', line 56 def resolve_proc(registry) return @proc unless named_hook? resolved = registry.get(@proc) raise ArgumentError, "Named hook :#{@proc} not found in registry" unless resolved resolved end |