Class: OllamaAgent::RuntimeCommandSystem::Session::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/runtime_command_system/session/events.rb

Instance Method Summary collapse

Constructor Details

#initializeEvents

Returns a new instance of Events.



7
8
9
# File 'lib/ollama_agent/runtime_command_system/session/events.rb', line 7

def initialize
  @handlers = Hash.new { |h, k| h[k] = [] }
end

Instance Method Details

#emit(event, payload = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/ollama_agent/runtime_command_system/session/events.rb', line 18

def emit(event, payload = {})
  @handlers[event.to_sym].each do |handler|
    handler.call(payload)
  rescue StandardError
    nil
  end
end

#on(event, &block) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/ollama_agent/runtime_command_system/session/events.rb', line 11

def on(event, &block)
  raise ArgumentError, "block required" unless block_given?

  @handlers[event.to_sym] << block
  self
end

#subscribed?(event) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ollama_agent/runtime_command_system/session/events.rb', line 26

def subscribed?(event)
  @handlers[event.to_sym].any?
end