Class: PusherFake::Channel::Public
- Inherits:
-
Object
- Object
- PusherFake::Channel::Public
- Defined in:
- lib/pusher-fake/channel/public.rb
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.
Constructor Details
#initialize(name) ⇒ Public
Create a new PusherFake::Channel::Public object.
13 14 15 16 |
# File 'lib/pusher-fake/channel/public.rb', line 13 def initialize(name) @name = name @connections = [] end |
Instance Attribute Details
#connections ⇒ Array (readonly)
Returns Connections in this channel.
5 6 7 |
# File 'lib/pusher-fake/channel/public.rb', line 5 def connections @connections end |
#name ⇒ String (readonly)
Returns The channel name.
8 9 10 |
# File 'lib/pusher-fake/channel/public.rb', line 8 def name @name end |
Instance Method Details
#add(connection, options = {}) ⇒ Object
Add the connection to the channel.
22 23 24 |
# File 'lib/pusher-fake/channel/public.rb', line 22 def add(connection, = {}) subscription_succeeded(connection, ) end |
#emit(event, data, options = {}) ⇒ Object
Emit an event to the channel.
30 31 32 33 34 35 36 |
# File 'lib/pusher-fake/channel/public.rb', line 30 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.
42 43 44 |
# File 'lib/pusher-fake/channel/public.rb', line 42 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.
51 52 53 54 55 56 57 |
# File 'lib/pusher-fake/channel/public.rb', line 51 def remove(connection) connections.delete(connection) if connections.empty? trigger("channel_vacated", channel: name) end end |
#subscription_data ⇒ Hash
This method is abstract.
Return subscription data for the channel.
63 64 65 |
# File 'lib/pusher-fake/channel/public.rb', line 63 def subscription_data {} end |