Class: OllamaAgent::RuntimeCommandSystem::Dispatch::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/runtime_command_system/dispatch/dispatcher.rb

Instance Method Summary collapse

Constructor Details

#initializeDispatcher

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

Returns:

  • (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