Class: Lanes::API::PubSub

Inherits:
Cable::Channel show all
Defined in:
lib/lanes/api/pub_sub.rb

Constant Summary collapse

PREFIX =
'ps:'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.publish(channel, data) ⇒ Object



18
19
20
21
# File 'lib/lanes/api/pub_sub.rb', line 18

def self.publish(channel, data)
    ActionCable.server.broadcast PREFIX + channel,
                                 data.merge(channel: channel)
end

Instance Method Details

#off(data) ⇒ Object



11
12
13
14
15
16
# File 'lib/lanes/api/pub_sub.rb', line 11

def off(data)
    channel = PREFIX + data['channel']
    cb = pubsub.instance_variable_get('@listener')
           .instance_variable_get('@subscribers')[channel].first
    pubsub.unsubscribe(channel, cb)
end

#on(data) ⇒ Object



6
7
8
9
# File 'lib/lanes/api/pub_sub.rb', line 6

def on(data)
    channel = PREFIX + data['channel']
    stream_from channel
end