Class: Lanes::API::PubSub
- Inherits:
-
Cable::Channel
- Object
- ActionCable::Channel::Base
- Cable::Channel
- Lanes::API::PubSub
- Defined in:
- lib/lanes/api/pub_sub.rb
Constant Summary collapse
- PREFIX =
'ps:'
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.channel_prefix ⇒ Object
25 26 27 |
# File 'lib/lanes/api/pub_sub.rb', line 25 def self.channel_prefix PREFIX end |
.publish(channel, data) ⇒ Object
20 21 22 23 |
# 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 |
Instance Method Details
#channel_prefix ⇒ Object
29 30 31 |
# File 'lib/lanes/api/pub_sub.rb', line 29 def channel_prefix PREFIX end |
#off(data) ⇒ Object
13 14 15 16 17 18 |
# 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) ⇒ Object
9 10 11 |
# File 'lib/lanes/api/pub_sub.rb', line 9 def on(data) stream_from channel_prefix + data['channel'] end |