class Lanes::API::PubSub

Constants

PREFIX

Public Class Methods

channel_prefix() click to toggle source
# File lib/lanes/api/pub_sub.rb, line 25
def self.channel_prefix
    PREFIX
end
publish(channel, data) click to toggle source
# File lib/lanes/api/pub_sub.rb, line 20
def self.publish(channel, data)
    channel = channel_prefix + channel
    ActionCable.server.broadcast(channel, data.merge(channel: channel))
end

Public Instance Methods

channel_prefix() click to toggle source
# File lib/lanes/api/pub_sub.rb, line 29
def channel_prefix
    PREFIX
end
off(data) click to toggle source
# File lib/lanes/api/pub_sub.rb, line 13
def off(data)
    channel = channel_prefix + data['channel']
    cb = pubsub.instance_variable_get('@listener')
           .instance_variable_get('@subscribers')[channel].first
    pubsub.unsubscribe(channel, cb)
end
on(data) click to toggle source
# File lib/lanes/api/pub_sub.rb, line 9
def on(data)
    stream_from channel_prefix + data['channel']
end