Class: OllamaAgent::RuntimeCommandSystem::Dispatch::Dispatcher
- Inherits:
-
Object
- Object
- OllamaAgent::RuntimeCommandSystem::Dispatch::Dispatcher
- Defined in:
- lib/ollama_agent/runtime_command_system/dispatch/dispatcher.rb
Instance Method Summary collapse
- #dispatch(ast, session:) ⇒ Object
- #handles?(command_name) ⇒ Boolean
-
#initialize ⇒ Dispatcher
constructor
A new instance of Dispatcher.
- #register(command_name, handler) ⇒ Object
Constructor Details
#initialize ⇒ Dispatcher
Returns a new instance of Dispatcher.
7 8 9 |
# File 'lib/ollama_agent/runtime_command_system/dispatch/dispatcher.rb', line 7 def initialize @handlers = {} end |
Instance Method Details
#dispatch(ast, session:) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/ollama_agent/runtime_command_system/dispatch/dispatcher.rb', line 20 def dispatch(ast, session:) handler = @handlers[normalize(ast.name)] return { handled: false } unless handler result = handler.call(ast: ast, session: session) (result || {}).merge(handled: true) end |
#handles?(command_name) ⇒ Boolean
16 17 18 |
# File 'lib/ollama_agent/runtime_command_system/dispatch/dispatcher.rb', line 16 def handles?(command_name) @handlers.key?(normalize(command_name)) end |
#register(command_name, handler) ⇒ Object
11 12 13 14 |
# File 'lib/ollama_agent/runtime_command_system/dispatch/dispatcher.rb', line 11 def register(command_name, handler) @handlers[normalize(command_name)] = handler self end |