Class: Hippo::API::PubSub
- Inherits:
-
ActionCable::Channel::Base
- Object
- ActionCable::Channel::Base
- Hippo::API::PubSub
- Defined in:
- lib/hippo/api/pub_sub.rb
Constant Summary collapse
- PREFIX =
'ps:'
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.channel_prefix ⇒ Object
28 29 30 |
# File 'lib/hippo/api/pub_sub.rb', line 28 def self.channel_prefix PREFIX end |
.publish(channel, data) ⇒ Object
23 24 25 26 |
# File 'lib/hippo/api/pub_sub.rb', line 23 def self.publish(channel, data) channel = channel_prefix + channel ActionCable.server.broadcast(channel, data.merge(channel: channel)) end |
Instance Method Details
#channel_prefix ⇒ Object
32 33 34 |
# File 'lib/hippo/api/pub_sub.rb', line 32 def channel_prefix PREFIX end |
#off(data) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/hippo/api/pub_sub.rb', line 15 def off(data) channel = channel_prefix + data['channel'] subscribers = pubsub .instance_variable_get('@listener') .instance_variable_get('@subscribers')[channel] pubsub.unsubscribe(channel, subscribers.first) if subscribers.any? end |