Class: Mistri::Sinks::ActionCable

Inherits:
Object
  • Object
show all
Defined in:
lib/mistri/sinks/action_cable.rb

Overview

Broadcasts every event to an Action Cable stream as its to_h shape. The server resolves lazily at first call, so this file loads without Rails; pass server: explicitly to use another broadcaster.

sink = Mistri::Sinks::ActionCable.new("agent_#{session.id}")
agent.run(input, &sink)

Instance Method Summary collapse

Constructor Details

#initialize(stream, server: nil) ⇒ ActionCable

Returns a new instance of ActionCable.



12
13
14
15
# File 'lib/mistri/sinks/action_cable.rb', line 12

def initialize(stream, server: nil)
  @stream = stream
  @server = server
end

Instance Method Details

#call(event) ⇒ Object



17
18
19
# File 'lib/mistri/sinks/action_cable.rb', line 17

def call(event)
  server.broadcast(@stream, event.to_h)
end

#to_procObject



21
# File 'lib/mistri/sinks/action_cable.rb', line 21

def to_proc = method(:call).to_proc