Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve documentation.

  • Loading branch information...
commit 9854be07bbb458764d624ad78328959566161699 1 parent 2e999ab
@tristandunn authored
View
1  CHANGELOG.markdown
@@ -3,6 +3,7 @@
## 0.1.4 — Unreleased
* Upgraded the Pusher JS client to version 1.12.1. (Tristan Dunn)
+* Improve documentation. (Tristan Dunn)
## 0.1.3 — July 9, 2012
View
8 lib/pusher-fake/channel.rb
@@ -1,9 +1,13 @@
module PusherFake
module Channel
class << self
+ # Name matcher for private channels.
PRIVATE_CHANNEL_MATCHER = /^private-/.freeze
+
+ # Name matcher for presence channels.
PRESENCE_CHANNEL_MATCHER = /^presence-/.freeze
+ # @return [Hash] Cache of existing channels.
attr_accessor :channels
# Create a channel, determining the type by the name.
@@ -39,6 +43,10 @@ def reset
private
+ # 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.
def class_for(name)
if name =~ PRIVATE_CHANNEL_MATCHER
Private
View
9 lib/pusher-fake/channel/presence.rb
@@ -13,7 +13,7 @@ def initialize(name)
@members = {}
end
- # Removes the +connection+ from the channel and notifies the channel.
+ # Remove the +connection+ from the channel and notify the channel.
#
# @param [Connection] connection The connection to remove.
def remove(connection)
@@ -22,7 +22,7 @@ def remove(connection)
emit("pusher_internal:member_removed", members.delete(connection))
end
- # Returns a hash containing presence information for the channel.
+ # Return a hash containing presence information for the channel.
#
# @return [Hash] Hash containing presence information.
def subscription_data
@@ -37,6 +37,11 @@ def subscription_data
private
+ # Store the member data for the connection and notify connections a
+ # member was added.
+ #
+ # @param [Connection] connection The connection a subscription succeeded for.
+ # @param [Hash] options The options for the channel.
def subscription_succeeded(connection, options = {})
members[connection] = Yajl::Parser.parse(options[:channel_data], symbolize_keys: true)
View
15 lib/pusher-fake/channel/public.rb
@@ -23,7 +23,7 @@ def add(connection, options = {})
subscription_succeeded(connection, options)
end
- # Emits an event to the channel.
+ # Emit an event to the channel.
#
# @param [String] event The event name.
# @param [Hash] data The event data.
@@ -33,7 +33,7 @@ def emit(event, data)
end
end
- # Determines if the +connection+ is in the channel.
+ # Determine if the +connection+ is in the channel.
#
# @param [Connection] connection The connection.
# @return [Boolean] +true+ if the connection is in the channel, +false+ otherwise.
@@ -41,19 +41,28 @@ def includes?(connection)
connections.index(connection)
end
- # Removes the +connection+ from the channel.
+ # Remove the +connection+ from the channel.
#
# @param [Connection] connection The connection to remove.
def remove(connection)
connections.delete(connection)
end
+ # Return subscription data for the channel.
+ #
+ # @abstract
+ # @return [Hash] Subscription data for the channel.
def subscription_data
{}
end
private
+ # Notify the channel of the successful subscription and add the
+ # connection to the channel.
+ #
+ # @param [Connection] connection The connection a subscription succeeded for.
+ # @param [Hash] options The options for the channel.
def subscription_succeeded(connection, options = {})
connection.emit("pusher_internal:subscription_succeeded", subscription_data, name)
connections.push(connection)
View
6 lib/pusher-fake/connection.rb
@@ -14,7 +14,7 @@ def initialize(socket)
#
# @param [String] event The event name.
# @param [Hash] data The event data.
- # @param [String] The channel name.
+ # @param [String] channel The channel name.
def emit(event, data = {}, channel = nil)
message = { event: event, data: data }
message[:channel] = channel if channel
@@ -23,12 +23,12 @@ def emit(event, data = {}, channel = nil)
socket.send(message)
end
- # Notifies the Pusher client that a connection has been established.
+ # Notify the Pusher client that a connection has been established.
def establish
emit("pusher:connection_established", socket_id: socket.object_id)
end
- # Processes an event.
+ # Process an event.
#
# @param [String] data The event data as JSON.
def process(data)
View
7 lib/pusher-fake/server.rb
@@ -36,10 +36,17 @@ def self.start_web_server
private
+ # Convenience method for access the configuration object.
+ #
+ # @return [Configuration] The configuration object.
def self.configuration
PusherFake.configuration
end
+ # Return a hash of options for the socket server based on
+ # the configuration.
+ #
+ # @return [Hash] The socket server configuration options.
def self.socket_server_options
{ host: configuration.socket_host,
port: configuration.socket_port }
Please sign in to comment.
Something went wrong with that request. Please try again.