celluloid_pubsub 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,56 @@
1
1
  require_relative './reactor'
2
2
  module CelluloidPubsub
3
+ # webserver to which socket connects should connect to .
4
+ # the server will dispatch each request into a new Reactor
5
+ # which will handle the action based on the message
6
+ # @!attribute options
7
+ # @return [Hash] options used to configure the webserver
8
+ # @option options [String]:hostname The hostname on which the webserver runs on
9
+ # @option options [Integer] :port The port on which the webserver runs on
10
+ # @option options [String] :path The request path that the webserver accepts
11
+ # @option options [Boolean] :spy Enable this only if you want to enable debugging for the webserver
12
+ #
13
+ # @!attribute subscribers
14
+ # @return [Hash] The hostname on which the webserver runs on
15
+ #
16
+ # @!attribute backlog
17
+ # @return [Integer] Determines how many connections can be used
18
+ # Defaults to 1024
19
+ #
20
+ # @!attribute hostname
21
+ # @return [String] The hostname on which the webserver runs on
22
+ #
23
+ # @!attribute port
24
+ # @return [String] The port on which the webserver runs on
25
+ #
26
+ # @!attribute path
27
+ # @return [String] The hostname on which the webserver runs on
28
+ #
29
+ # @!attribute spy
30
+ # @return [Boolean] Enable this only if you want to enable debugging for the webserver
3
31
  class WebServer < Reel::Server::HTTP
4
32
  include Celluloid::Logger
5
33
 
34
+ # The hostname on which the webserver runs on by default
6
35
  HOST = '0.0.0.0'
36
+ # The port on which the webserver runs on by default
7
37
  PORT = 1234
38
+ # The request path that the webserver accepts by default
8
39
  PATH = '/ws'
9
40
 
10
41
  attr_accessor :options, :subscribers, :backlog, :hostname, :port, :path, :spy
11
42
 
43
+ # receives a list of options that are used to configure the webserver
44
+ #
45
+ # @param [Hash] options the options that can be used to connect to webser and send additional data
46
+ # @option options [String]:hostname The hostname on which the webserver runs on
47
+ # @option options [Integer] :port The port on which the webserver runs on
48
+ # @option options [String] :path The request path that the webserver accepts
49
+ # @option options [Boolean] :spy Enable this only if you want to enable debugging for the webserver
50
+ #
51
+ # @return [void]
52
+ #
53
+ # @api public
12
54
  def initialize(options = {})
13
55
  parse_options(options)
14
56
  @subscribers = {}
@@ -16,6 +58,18 @@ module CelluloidPubsub
16
58
  super(@hostname, @port, { spy: @spy, backlog: @backlog }, &method(:on_connection))
17
59
  end
18
60
 
61
+ # receives a list of options that are used to configure the webserver
62
+ #
63
+ # @param [Hash] options the options that can be used to connect to webser and send additional data
64
+ # @option options [String]:hostname The hostname on which the webserver runs on
65
+ # @option options [Integer] :port The port on which the webserver runs on
66
+ # @option options [String] :path The request path that the webserver accepts
67
+ # @option options [Boolean] :spy Enable this only if you want to enable debugging for the webserver
68
+ # @option options [Integer]:backlog How many connections the server accepts
69
+ #
70
+ # @return [void]
71
+ #
72
+ # @api public
19
73
  def parse_options(options)
20
74
  raise 'Options is not a hash ' unless options.is_a?(Hash)
21
75
  @options = options.stringify_keys
@@ -26,14 +80,32 @@ module CelluloidPubsub
26
80
  @spy = @options.fetch(:spy, false)
27
81
  end
28
82
 
83
+ # checks if debug is enabled
84
+ #
85
+ # @return [boolean]
86
+ #
87
+ # @api public
29
88
  def debug_enabled?
30
89
  self.class.debug_enabled?
31
90
  end
32
91
 
92
+ # checks if debug is enabled
93
+ #
94
+ # @return [boolean]
95
+ #
96
+ # @api public
33
97
  def self.debug_enabled?
34
98
  ENV['DEBUG_CELLULOID'].present? && (ENV['DEBUG_CELLULOID'] == 'true' || ENV['DEBUG_CELLULOID'] == true)
35
99
  end
36
100
 
101
+ # checks if debug is enabled
102
+ #
103
+ # @param [String] current_topic The Channel to which the reactor instance {CelluloidPubsub::Rector} will publish the message to
104
+ # @param [Object] message
105
+ #
106
+ # @return [void]
107
+ #
108
+ # @api public
37
109
  def publish_event(current_topic, message)
38
110
  return if current_topic.blank? || message.blank?
39
111
  @subscribers[current_topic].each do |hash|
@@ -41,6 +113,19 @@ module CelluloidPubsub
41
113
  end
42
114
  end
43
115
 
116
+ # callback that will execute when receiving new conections
117
+ # If the connections is a websocket will call method {#route_websocket}
118
+ # and if the connection is HTTP will call method {#route_request}
119
+ # For websocket connections , the connection is detached from the server and dispatched to another actor
120
+ #
121
+ # @see #route_websocket
122
+ # @see #route_request
123
+ #
124
+ # @param [Reel::WebSocket] connection The connection that was made to the webserver
125
+ #
126
+ # @return [void]
127
+ #
128
+ # @api public
44
129
  def on_connection(connection)
45
130
  while request = connection.request
46
131
  if request.websocket?
@@ -62,11 +147,29 @@ module CelluloidPubsub
62
147
  end
63
148
  end
64
149
 
150
+ # HTTP connections are not accepted so this method will show 404 message "Not Found"
151
+ #
152
+ # @param [Reel::WebSocket] connection The HTTP connection that was received
153
+ # @param [Reel::Request] request The request that was made to the webserver and contains the type , the url, and the parameters
154
+ #
155
+ # @return [void]
156
+ #
157
+ # @api public
65
158
  def route_request(connection, request)
66
159
  info "404 Not Found: #{request.path}" if debug_enabled?
67
160
  connection.respond :not_found, 'Not found'
68
161
  end
69
162
 
163
+ # If the socket url matches with the one accepted by the server, it will dispatch the socket connection to a new reactor {CelluloidPubsub::Reactor#work}
164
+ # The new actor is linked to the webserver
165
+ #
166
+ # @see CelluloidPubsub::Reactor#work
167
+ #
168
+ # @param [Reel::WebSocket] socket The web socket connection that was received
169
+ #
170
+ # @return [void]
171
+ #
172
+ # @api public
70
173
  def route_websocket(socket)
71
174
  if socket.url == @path
72
175
  info 'Reactor handles new socket connection' if debug_enabled?
@@ -79,6 +182,15 @@ module CelluloidPubsub
79
182
  end
80
183
  end
81
184
 
185
+ # If the message can be parsed into a Hash it will respond to the reactor's websocket connection with the same message in JSON format
186
+ # otherwise will try send the message how it is and escaped into JSON format
187
+ #
188
+ # @param [CelluloidPubsub::Reactor] reactor The reactor that received an unhandled message
189
+ # @param [Object] data The message that the reactor could not handle
190
+ #
191
+ # @return [void]
192
+ #
193
+ # @api public
82
194
  def handle_dispatched_message(reactor, data)
83
195
  debug "Webserver trying to dispatch message #{data.inspect}" if debug_enabled?
84
196
  message = reactor.parse_json_data(data)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid
@@ -339,25 +339,33 @@ dependencies:
339
339
  - !ruby/object:Gem::Version
340
340
  version: 0.8.7
341
341
  - !ruby/object:Gem::Dependency
342
- name: yardstick
342
+ name: inch
343
343
  requirement: !ruby/object:Gem::Requirement
344
344
  requirements:
345
345
  - - ~>
346
346
  - !ruby/object:Gem::Version
347
- version: 0.9.9
348
- - - '>='
349
- - !ruby/object:Gem::Version
350
- version: 0.9.9
347
+ version: 0.5.10
351
348
  type: :development
352
349
  prerelease: false
353
350
  version_requirements: !ruby/object:Gem::Requirement
354
351
  requirements:
355
352
  - - ~>
356
353
  - !ruby/object:Gem::Version
357
- version: 0.9.9
358
- - - '>='
354
+ version: 0.5.10
355
+ - !ruby/object:Gem::Dependency
356
+ name: guard-inch
357
+ requirement: !ruby/object:Gem::Requirement
358
+ requirements:
359
+ - - ~>
360
+ - !ruby/object:Gem::Version
361
+ version: 0.1.0
362
+ type: :development
363
+ prerelease: false
364
+ version_requirements: !ruby/object:Gem::Requirement
365
+ requirements:
366
+ - - ~>
359
367
  - !ruby/object:Gem::Version
360
- version: 0.9.9
368
+ version: 0.1.0
361
369
  description: CelluloidPubsub is a simple ruby implementation of publish subscribe
362
370
  design patterns using celluloid actors and websockets, using Reel server for inter-process
363
371
  communication
@@ -388,6 +396,7 @@ files:
388
396
  - bin/erubis
389
397
  - bin/guard
390
398
  - bin/htmldiff
399
+ - bin/inch
391
400
  - bin/ldiff
392
401
  - bin/listen
393
402
  - bin/nokogiri
@@ -405,6 +414,7 @@ files:
405
414
  - bin/sass-convert
406
415
  - bin/scss
407
416
  - bin/scss-lint
417
+ - bin/sparkr
408
418
  - bin/term_display
409
419
  - bin/term_mandel
410
420
  - bin/thor
@@ -413,6 +423,27 @@ files:
413
423
  - bin/yardstick
414
424
  - bin/yri
415
425
  - celluloid_pubsub.gemspec
426
+ - doc/CelluloidPubsub.html
427
+ - doc/CelluloidPubsub/Client.html
428
+ - doc/CelluloidPubsub/Client/PubSubWorker.html
429
+ - doc/CelluloidPubsub/Reactor.html
430
+ - doc/CelluloidPubsub/Registry.html
431
+ - doc/CelluloidPubsub/VERSION.html
432
+ - doc/CelluloidPubsub/WebServer.html
433
+ - doc/_index.html
434
+ - doc/class_list.html
435
+ - doc/css/common.css
436
+ - doc/css/full_list.css
437
+ - doc/css/style.css
438
+ - doc/file.README.html
439
+ - doc/file_list.html
440
+ - doc/frames.html
441
+ - doc/index.html
442
+ - doc/js/app.js
443
+ - doc/js/full_list.js
444
+ - doc/js/jquery.js
445
+ - doc/method_list.html
446
+ - doc/top-level-namespace.html
416
447
  - examples/simple_test.rb
417
448
  - init.rb
418
449
  - lib/celluloid_pubsub.rb