class IRails::Comm

Comm is a new messaging system for bidirectional communication. Both kernel and front-end listens for messages.

Attributes

on_close[W]
on_msg[W]

Public Class Methods

comm() click to toggle source
# File lib/irails/comm.rb, line 9
def comm;   @comm   ||= {} end
new(target_name, comm_id = SecureRandom.uuid) click to toggle source
# File lib/irails/comm.rb, line 12
def initialize(target_name, comm_id = SecureRandom.uuid)
  @target_name, @comm_id = target_name, comm_id
end
target() click to toggle source
# File lib/irails/comm.rb, line 8
def target; @target ||= {} end

Public Instance Methods

close(**data) click to toggle source
# File lib/irails/comm.rb, line 25
def close(**data)
  Kernel.instance.session.send(:publish, :comm_close, comm_id: @comm_id, data: data)
  Comm.comm.delete(@comm_id)
end
handle_close(data) click to toggle source
# File lib/irails/comm.rb, line 42
def handle_close(data)
  @on_close.call(data) if @on_close
end
handle_msg(data) click to toggle source
# File lib/irails/comm.rb, line 38
def handle_msg(data)
  @on_msg.call(data) if @on_msg
end
on_close(&b) click to toggle source
# File lib/irails/comm.rb, line 34
def on_close(&b)
  @on_close = b
end
on_msg(&b) click to toggle source
# File lib/irails/comm.rb, line 30
def on_msg(&b)
  @on_msg = b
end
open(**data) click to toggle source
# File lib/irails/comm.rb, line 16
def open(**data)
  Kernel.instance.session.send(:publish, :comm_open, comm_id: @comm_id, data: data, target_name: @target_name)
  Comm.comm[@comm_id] = self
end
send(**data) click to toggle source
# File lib/irails/comm.rb, line 21
def send(**data)
  Kernel.instance.session.send(:publish, :comm_msg, comm_id: @comm_id, data: data)
end