Class: PusherFake::Channel::Public
- Inherits:
-
Object
- Object
- PusherFake::Channel::Public
- Defined in:
- lib/pusher-fake/channel/public.rb
Overview
A public channel.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connections ⇒ Array
readonly
Connections in this channel.
-
#name ⇒ String
readonly
The channel name.
Instance Method Summary collapse
-
#add(connection, options = {}) ⇒ Object
Add the connection to the channel.
-
#emit(event, data, options = {}) ⇒ Object
Emit an event to the channel.
-
#includes?(connection) ⇒ Boolean
Determine if the
connection
is in the channel. -
#initialize(name) ⇒ Public
constructor
Create a new Public object.
-
#remove(connection) ⇒ Object
Remove the
connection
from the channel. -
#subscription_data ⇒ Hash
abstract
Return subscription data for the channel.
- #trigger(name, data = {}) ⇒ Object
Constructor Details
#initialize(name) ⇒ Public
Create a new PusherFake::Channel::Public object.
16 17 18 19 |
# File 'lib/pusher-fake/channel/public.rb', line 16 def initialize(name) @name = name @connections = [] end |
Instance Attribute Details
#connections ⇒ Array (readonly)
Returns Connections in this channel.
8 9 10 |
# File 'lib/pusher-fake/channel/public.rb', line 8 def connections @connections end |
#name ⇒ String (readonly)
Returns The channel name.
11 12 13 |
# File 'lib/pusher-fake/channel/public.rb', line 11 def name @name end |
Instance Method Details
#add(connection, options = {}) ⇒ Object
Add the connection to the channel.
25 26 27 |
# File 'lib/pusher-fake/channel/public.rb', line 25 def add(connection, = {}) subscription_succeeded(connection, ) end |
#emit(event, data, options = {}) ⇒ Object
Emit an event to the channel.
33 34 35 36 37 38 39 |
# File 'lib/pusher-fake/channel/public.rb', line 33 def emit(event, data, = {}) connections.each do |connection| unless connection.id == [:socket_id] connection.emit(event, data, name) end end end |
#includes?(connection) ⇒ Boolean
Determine if the connection
is in the channel.
45 46 47 |
# File 'lib/pusher-fake/channel/public.rb', line 45 def includes?(connection) connections.index(connection) end |
#remove(connection) ⇒ Object
Remove the connection
from the channel.
If it is the last connection, trigger the channel_vacated webhook.
54 55 56 57 58 |
# File 'lib/pusher-fake/channel/public.rb', line 54 def remove(connection) connections.delete(connection) trigger("channel_vacated", channel: name) if connections.empty? end |
#subscription_data ⇒ Hash
This method is abstract.
Return subscription data for the channel.
64 65 66 |
# File 'lib/pusher-fake/channel/public.rb', line 64 def subscription_data {} end |
#trigger(name, data = {}) ⇒ Object
68 69 70 |
# File 'lib/pusher-fake/channel/public.rb', line 68 def trigger(name, data = {}) PusherFake::Webhook.trigger(name, data) end |