Module: PusherFake::Channel

Defined in:
lib/pusher-fake/channel.rb,
lib/pusher-fake/channel/public.rb,
lib/pusher-fake/channel/private.rb,
lib/pusher-fake/channel/presence.rb

Overview

Channel creation and management.

Defined Under Namespace

Classes: Presence, Private, Public

Constant Summary collapse

PRIVATE_CHANNEL_PREFIX =

Prefix for private channels.

"private-"
PRESENCE_CHANNEL_PREFIX =

Prefix for presence channels.

"presence-"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.channelsHash

Returns Cache of existing channels.

Returns:

  • (Hash)

    Cache of existing channels.



21
22
23
# File 'lib/pusher-fake/channel.rb', line 21

def channels
  @channels ||= {}
end

Class Method Details

.factory(name) ⇒ Public|Private

Create a channel, determining the type by the name.

Parameters:

  • name (String)

    The channel name.

Returns:



29
30
31
32
# File 'lib/pusher-fake/channel.rb', line 29

def factory(name)
  self.channels       ||= {}
  self.channels[name] ||= class_for(name).new(name)
end

.remove(connection) ⇒ Object

Remove a connection from all channels.

Also deletes the channel if it is empty.

Parameters:

  • connection (Connection)

    The connection to remove.



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pusher-fake/channel.rb', line 39

def remove(connection)
  return if channels.nil?

  channels.each do |name, channel|
    channel.remove(connection)

    if channels[name].connections.empty?
      channels.delete(name)
    end
  end
end

.resetObject

Reset the channel cache.



52
53
54
# File 'lib/pusher-fake/channel.rb', line 52

def reset
  self.channels = {}
end