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

Defined Under Namespace

Classes: Presence, Private, Public

Constant Summary collapse

PRIVATE_CHANNEL_MATCHER =

Name matcher for private channels.

/\Aprivate-/.freeze
PRESENCE_CHANNEL_MATCHER =

Name matcher for presence channels.

/\Apresence-/.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.channelsHash

Returns Cache of existing channels.

Returns:

  • (Hash)

    Cache of existing channels.



15
16
17
# File 'lib/pusher-fake/channel.rb', line 15

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:



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

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.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pusher-fake/channel.rb', line 31

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.



44
45
46
# File 'lib/pusher-fake/channel.rb', line 44

def reset
  self.channels = {}
end