module PusherFake::Channel

Channel creation and management.

Constants

PRESENCE_CHANNEL_PREFIX

Prefix for presence channels.

PRIVATE_CHANNEL_PREFIX

Prefix for private channels.

Attributes

channels[W]

@return [Hash] Cache of existing channels.

Public Class Methods

channels() click to toggle source

@return [Hash] Cache of existing channels.

# File lib/pusher-fake/channel.rb, line 21
def channels
  @channels ||= {}
end
factory(name) click to toggle source

Create a channel, determining the type by the name.

@param [String] name The channel name. @return [Public|Private] The channel object.

# File lib/pusher-fake/channel.rb, line 29
def factory(name)
  self.channels       ||= {}
  self.channels[name] ||= class_for(name).new(name)
end
remove(connection) click to toggle source

Remove a connection from all channels.

Also deletes the channel if it is empty.

@param [Connection] connection The connection to remove.

# 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
reset() click to toggle source

Reset the channel cache.

# File lib/pusher-fake/channel.rb, line 52
def reset
  self.channels = {}
end

Private Class Methods

class_for(name) click to toggle source

Determine the channel class to use based on the channel name.

@param [String] name The name of the channel. @return [Class] The class to use for the channel.

# File lib/pusher-fake/channel.rb, line 62
def class_for(name)
  if name.start_with?(PRIVATE_CHANNEL_PREFIX)
    Private
  elsif name.start_with?(PRESENCE_CHANNEL_PREFIX)
    Presence
  else
    Public
  end
end