Class: OllamaAgent::RuntimeCommandSystem::Session::Events
- Inherits:
-
Object
- Object
- OllamaAgent::RuntimeCommandSystem::Session::Events
- Defined in:
- lib/ollama_agent/runtime_command_system/session/events.rb
Instance Method Summary collapse
- #emit(event, payload = {}) ⇒ Object
-
#initialize ⇒ Events
constructor
A new instance of Events.
- #on(event, &block) ⇒ Object
- #subscribed?(event) ⇒ Boolean
Constructor Details
#initialize ⇒ Events
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
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
26 27 28 |
# File 'lib/ollama_agent/runtime_command_system/session/events.rb', line 26 def subscribed?(event) @handlers[event.to_sym].any? end |