Class: VectorMCP::Middleware::Hook
- Inherits:
-
Object
- Object
- VectorMCP::Middleware::Hook
- Defined in:
- lib/vector_mcp/middleware/hook.rb
Overview
Represents a single middleware hook with priority and execution logic
Constant Summary collapse
- DEFAULT_PRIORITY =
Default priority for middleware (lower numbers execute first)
100
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#hook_type ⇒ Object
readonly
Returns the value of attribute hook_type.
-
#middleware_class ⇒ Object
readonly
Returns the value of attribute middleware_class.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compare hooks for sorting by priority.
-
#execute(context) ⇒ void
Execute this hook with the given context.
-
#initialize(middleware_class, hook_type, priority: DEFAULT_PRIORITY, conditions: {}) ⇒ Hook
constructor
A new instance of Hook.
-
#should_execute?(context) ⇒ Boolean
Check if this hook should execute for the given context.
Constructor Details
#initialize(middleware_class, hook_type, priority: DEFAULT_PRIORITY, conditions: {}) ⇒ Hook
Returns a new instance of Hook.
16 17 18 19 20 21 22 23 24 |
# File 'lib/vector_mcp/middleware/hook.rb', line 16 def initialize(middleware_class, hook_type, priority: DEFAULT_PRIORITY, conditions: {}) @middleware_class = middleware_class @hook_type = hook_type.to_s @priority = priority @conditions = conditions validate_hook_type! validate_middleware_class! end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
7 8 9 |
# File 'lib/vector_mcp/middleware/hook.rb', line 7 def conditions @conditions end |
#hook_type ⇒ Object (readonly)
Returns the value of attribute hook_type.
7 8 9 |
# File 'lib/vector_mcp/middleware/hook.rb', line 7 def hook_type @hook_type end |
#middleware_class ⇒ Object (readonly)
Returns the value of attribute middleware_class.
7 8 9 |
# File 'lib/vector_mcp/middleware/hook.rb', line 7 def middleware_class @middleware_class end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
7 8 9 |
# File 'lib/vector_mcp/middleware/hook.rb', line 7 def priority @priority end |
Instance Method Details
#<=>(other) ⇒ Integer
Compare hooks for sorting by priority
55 56 57 |
# File 'lib/vector_mcp/middleware/hook.rb', line 55 def <=>(other) @priority <=> other.priority end |
#execute(context) ⇒ void
This method returns an undefined value.
Execute this hook with the given context
29 30 31 32 33 34 35 36 37 |
# File 'lib/vector_mcp/middleware/hook.rb', line 29 def execute(context) return unless should_execute?(context) # Create middleware instance and execute hook middleware_instance = create_middleware_instance(context) execute_hook_method(middleware_instance, context) rescue StandardError => e handle_hook_error(e, context) end |
#should_execute?(context) ⇒ Boolean
Check if this hook should execute for the given context
42 43 44 45 46 47 48 49 50 |
# File 'lib/vector_mcp/middleware/hook.rb', line 42 def should_execute?(context) return false if context.skip_remaining_hooks # Check operation type match return false unless matches_operation_type?(context) # Check custom conditions @conditions.all? { |key, value| condition_matches?(key, value, context) } end |