celluloid_pubsub 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +2 -2
  4. data/Rakefile +6 -3
  5. data/celluloid_pubsub.gemspec +1 -1
  6. data/lib/celluloid_pubsub/reactor.rb +11 -15
  7. data/lib/celluloid_pubsub/version.rb +1 -1
  8. data/lib/celluloid_pubsub/web_server.rb +3 -0
  9. data/spec/lib/celluloid_pubsub/client_pubsub_spec.rb +128 -0
  10. data/spec/lib/celluloid_pubsub/reactor_spec.rb +208 -0
  11. data/spec/lib/celluloid_pubsub/registry_spec.rb +4 -0
  12. data/spec/lib/celluloid_pubsub/web_server_spec.rb +43 -0
  13. data/spec/spec_helper.rb +8 -0
  14. metadata +12 -70
  15. data/bin/appraisal +0 -16
  16. data/bin/autospec +0 -16
  17. data/bin/bundler +0 -16
  18. data/bin/cdiff +0 -16
  19. data/bin/coderay +0 -16
  20. data/bin/colortab +0 -16
  21. data/bin/coveralls +0 -16
  22. data/bin/decolor +0 -16
  23. data/bin/erubis +0 -16
  24. data/bin/guard +0 -16
  25. data/bin/htmldiff +0 -16
  26. data/bin/inch +0 -16
  27. data/bin/ldiff +0 -16
  28. data/bin/listen +0 -16
  29. data/bin/nokogiri +0 -16
  30. data/bin/phare +0 -16
  31. data/bin/pry +0 -16
  32. data/bin/rackup +0 -16
  33. data/bin/rails +0 -16
  34. data/bin/rake +0 -16
  35. data/bin/restclient +0 -16
  36. data/bin/rspec +0 -16
  37. data/bin/rubocop +0 -16
  38. data/bin/ruby-parse +0 -16
  39. data/bin/ruby-rewrite +0 -16
  40. data/bin/sass +0 -16
  41. data/bin/sass-convert +0 -16
  42. data/bin/scss +0 -16
  43. data/bin/scss-lint +0 -16
  44. data/bin/sparkr +0 -16
  45. data/bin/term_display +0 -16
  46. data/bin/term_mandel +0 -16
  47. data/bin/thor +0 -16
  48. data/bin/yard +0 -16
  49. data/bin/yardoc +0 -16
  50. data/bin/yardstick +0 -16
  51. data/bin/yri +0 -16
  52. data/doc/CelluloidPubsub/Client/PubSubWorker.html +0 -3676
  53. data/doc/CelluloidPubsub/Client.html +0 -340
  54. data/doc/CelluloidPubsub/Reactor.html +0 -3502
  55. data/doc/CelluloidPubsub/Registry.html +0 -234
  56. data/doc/CelluloidPubsub/VERSION.html +0 -204
  57. data/doc/CelluloidPubsub/WebServer.html +0 -4275
  58. data/doc/CelluloidPubsub.html +0 -225
  59. data/doc/_index.html +0 -184
  60. data/doc/class_list.html +0 -58
  61. data/doc/css/common.css +0 -1
  62. data/doc/css/full_list.css +0 -57
  63. data/doc/css/style.css +0 -339
  64. data/doc/file.README.html +0 -150
  65. data/doc/file_list.html +0 -60
  66. data/doc/frames.html +0 -26
  67. data/doc/index.html +0 -150
  68. data/doc/js/app.js +0 -219
  69. data/doc/js/full_list.js +0 -181
  70. data/doc/js/jquery.js +0 -4
  71. data/doc/method_list.html +0 -357
  72. data/doc/top-level-namespace.html +0 -112
@@ -1,3676 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
- <title>
7
- Class: CelluloidPubsub::Client::PubSubWorker
8
-
9
- &mdash; Documentation by YARD 0.8.7.6
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- hasFrames = window.top.frames.main ? true : false;
19
- relpath = '../../';
20
- framesUrl = "../../frames.html#!CelluloidPubsub/Client/PubSubWorker.html";
21
- </script>
22
-
23
-
24
- <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
25
-
26
- <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
27
-
28
-
29
- </head>
30
- <body>
31
- <div id="header">
32
- <div id="menu">
33
-
34
- <a href="../../_index.html">Index (P)</a> &raquo;
35
- <span class='title'><span class='object_link'><a href="../../CelluloidPubsub.html" title="CelluloidPubsub (module)">CelluloidPubsub</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Client.html" title="CelluloidPubsub::Client (class)">Client</a></span></span>
36
- &raquo;
37
- <span class="title">PubSubWorker</span>
38
-
39
-
40
- <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
- </div>
42
-
43
- <div id="search">
44
-
45
- <a class="full_list_link" id="class_list_link"
46
- href="../../class_list.html">
47
- Class List
48
- </a>
49
-
50
- <a class="full_list_link" id="method_list_link"
51
- href="../../method_list.html">
52
- Method List
53
- </a>
54
-
55
- <a class="full_list_link" id="file_list_link"
56
- href="../../file_list.html">
57
- File List
58
- </a>
59
-
60
- </div>
61
- <div class="clear"></div>
62
- </div>
63
-
64
- <iframe id="search_frame"></iframe>
65
-
66
- <div id="content"><h1>Class: CelluloidPubsub::Client::PubSubWorker
67
-
68
-
69
-
70
- </h1>
71
-
72
- <dl class="box">
73
-
74
- <dt class="r1">Inherits:</dt>
75
- <dd class="r1">
76
- <span class="inheritName">Object</span>
77
-
78
- <ul class="fullTree">
79
- <li>Object</li>
80
-
81
- <li class="next">CelluloidPubsub::Client::PubSubWorker</li>
82
-
83
- </ul>
84
- <a href="#" class="inheritanceTree">show all</a>
85
-
86
- </dd>
87
-
88
-
89
-
90
-
91
-
92
-
93
- <dt class="r2">Includes:</dt>
94
- <dd class="r2">Celluloid, Celluloid::Logger</dd>
95
-
96
-
97
-
98
-
99
-
100
- <dt class="r1 last">Defined in:</dt>
101
- <dd class="r1 last">lib/celluloid_pubsub/client_pubsub.rb</dd>
102
-
103
- </dl>
104
- <div class="clear"></div>
105
-
106
- <h2>Overview</h2><div class="docstring">
107
- <div class="discussion">
108
-
109
- <p>worker that subscribes to a channel or publishes to a channel if it used to
110
- subscribe to a channel the worker will dispatch the messages to the actor
111
- that made the connection in the first place.</p>
112
-
113
-
114
- </div>
115
- </div>
116
- <div class="tags">
117
-
118
-
119
- </div>
120
-
121
-
122
-
123
- <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
124
- <ul class="summary">
125
-
126
- <li class="public ">
127
- <span class="summary_signature">
128
-
129
- <a href="#actor-instance_method" title="#actor (instance method)">- (Celluloid::Actor) <strong>actor</strong> </a>
130
-
131
-
132
-
133
- </span>
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
- <span class="summary_desc"><div class='inline'>
147
- <p>Actor to which callbacks will be delegated to.</p>
148
- </div></span>
149
-
150
- </li>
151
-
152
-
153
- <li class="public ">
154
- <span class="summary_signature">
155
-
156
- <a href="#client-instance_method" title="#client (instance method)">- (Celluloid::WebSocket::Client) <strong>client</strong> </a>
157
-
158
-
159
-
160
- </span>
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
- <span class="summary_desc"><div class='inline'>
174
- <p>A websocket client that is used to chat witht the webserver.</p>
175
- </div></span>
176
-
177
- </li>
178
-
179
-
180
- <li class="public ">
181
- <span class="summary_signature">
182
-
183
- <a href="#connect_blk-instance_method" title="#connect_blk (instance method)">- (Proc) <strong>connect_blk</strong> </a>
184
-
185
-
186
-
187
- </span>
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
- <span class="summary_desc"><div class='inline'>
201
- <p>Block that will execute after the connection is opened.</p>
202
- </div></span>
203
-
204
- </li>
205
-
206
-
207
- <li class="public ">
208
- <span class="summary_signature">
209
-
210
- <a href="#hostname-instance_method" title="#hostname (instance method)">- (String) <strong>hostname</strong> </a>
211
-
212
-
213
-
214
- </span>
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
- <span class="summary_desc"><div class='inline'>
228
- <p>The hostname on which the webserver runs on.</p>
229
- </div></span>
230
-
231
- </li>
232
-
233
-
234
- <li class="public ">
235
- <span class="summary_signature">
236
-
237
- <a href="#options-instance_method" title="#options (instance method)">- (Hash) <strong>options</strong> </a>
238
-
239
-
240
-
241
- </span>
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
- <span class="summary_desc"><div class='inline'>
255
- <p>The options that can be used to connect to webser and send additional data.</p>
256
- </div></span>
257
-
258
- </li>
259
-
260
-
261
- <li class="public ">
262
- <span class="summary_signature">
263
-
264
- <a href="#path-instance_method" title="#path (instance method)">- (String) <strong>path</strong> </a>
265
-
266
-
267
-
268
- </span>
269
-
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
- <span class="summary_desc"><div class='inline'>
282
- <p>The hostname on which the webserver runs on.</p>
283
- </div></span>
284
-
285
- </li>
286
-
287
-
288
- <li class="public ">
289
- <span class="summary_signature">
290
-
291
- <a href="#port-instance_method" title="#port (instance method)">- (String) <strong>port</strong> </a>
292
-
293
-
294
-
295
- </span>
296
-
297
-
298
-
299
-
300
-
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
- <span class="summary_desc"><div class='inline'>
309
- <p>The port on which the webserver runs on.</p>
310
- </div></span>
311
-
312
- </li>
313
-
314
-
315
- </ul>
316
-
317
-
318
-
319
-
320
-
321
- <h2>
322
- Instance Method Summary
323
- <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
324
- </h2>
325
-
326
- <ul class="summary">
327
-
328
- <li class="public ">
329
- <span class="summary_signature">
330
-
331
- <a href="#debug_enabled%3F-instance_method" title="#debug_enabled? (instance method)">- (boolean) <strong>debug_enabled?</strong> </a>
332
-
333
-
334
-
335
- </span>
336
-
337
-
338
-
339
-
340
-
341
-
342
-
343
-
344
-
345
- <span class="summary_desc"><div class='inline'>
346
- <p>checks if debug is enabled.</p>
347
- </div></span>
348
-
349
- </li>
350
-
351
-
352
- <li class="public ">
353
- <span class="summary_signature">
354
-
355
- <a href="#initialize-instance_method" title="#initialize (instance method)">- (void) <strong>initialize</strong>(options, &amp;connect_blk) </a>
356
-
357
-
358
-
359
- </span>
360
-
361
-
362
- <span class="note title constructor">constructor</span>
363
-
364
-
365
-
366
-
367
-
368
-
369
-
370
-
371
- <span class="summary_desc"><div class='inline'>
372
- <p>receives a list of options that are used to connect to the webserver and an
373
- actor to which the callbacks are delegated to when receiving messages from
374
- a channel.</p>
375
- </div></span>
376
-
377
- </li>
378
-
379
-
380
- <li class="public ">
381
- <span class="summary_signature">
382
-
383
- <a href="#on_close-instance_method" title="#on_close (instance method)">- (void) <strong>on_close</strong>(code, reason) </a>
384
-
385
-
386
-
387
- </span>
388
-
389
-
390
-
391
-
392
-
393
-
394
-
395
-
396
-
397
- <span class="summary_desc"><div class='inline'>
398
- <p>callback executes when connection closes.</p>
399
- </div></span>
400
-
401
- </li>
402
-
403
-
404
- <li class="public ">
405
- <span class="summary_signature">
406
-
407
- <a href="#on_message-instance_method" title="#on_message (instance method)">- (void) <strong>on_message</strong>(data) </a>
408
-
409
-
410
-
411
- </span>
412
-
413
-
414
-
415
-
416
-
417
-
418
-
419
-
420
-
421
- <span class="summary_desc"><div class='inline'>
422
- <p>callback executes when actor receives a message from a subscribed channel
423
- and parses the message using JSON.parse and dispatches the parsed message
424
- to the original actor that made the connection.</p>
425
- </div></span>
426
-
427
- </li>
428
-
429
-
430
- <li class="public ">
431
- <span class="summary_signature">
432
-
433
- <a href="#on_open-instance_method" title="#on_open (instance method)">- (void) <strong>on_open</strong> </a>
434
-
435
-
436
-
437
- </span>
438
-
439
-
440
-
441
-
442
-
443
-
444
-
445
-
446
-
447
- <span class="summary_desc"><div class='inline'>
448
- <p>callback executes after connection is opened and delegates action to actor.</p>
449
- </div></span>
450
-
451
- </li>
452
-
453
-
454
- <li class="public ">
455
- <span class="summary_signature">
456
-
457
- <a href="#parse_options-instance_method" title="#parse_options (instance method)">- (void) <strong>parse_options</strong>(options) </a>
458
-
459
-
460
-
461
- </span>
462
-
463
-
464
-
465
-
466
-
467
-
468
-
469
-
470
-
471
- <span class="summary_desc"><div class='inline'>
472
- <p>check the options list for values and sets default values if not found.</p>
473
- </div></span>
474
-
475
- </li>
476
-
477
-
478
- <li class="public ">
479
- <span class="summary_signature">
480
-
481
- <a href="#publish-instance_method" title="#publish (instance method)">- (void) <strong>publish</strong>(channel, data) </a>
482
-
483
-
484
-
485
- </span>
486
-
487
-
488
-
489
-
490
-
491
-
492
-
493
-
494
-
495
- <span class="summary_desc"><div class='inline'>
496
- <p>publishes to a channel some data (can be anything).</p>
497
- </div></span>
498
-
499
- </li>
500
-
501
-
502
- <li class="public ">
503
- <span class="summary_signature">
504
-
505
- <a href="#subscribe-instance_method" title="#subscribe (instance method)">- (void) <strong>subscribe</strong>(channel) </a>
506
-
507
-
508
-
509
- </span>
510
-
511
-
512
-
513
-
514
-
515
-
516
-
517
-
518
-
519
- <span class="summary_desc"><div class='inline'>
520
- <p>subscribes to a channel .</p>
521
- </div></span>
522
-
523
- </li>
524
-
525
-
526
- </ul>
527
-
528
-
529
-
530
-
531
- <div id="constructor_details" class="method_details_list">
532
- <h2>Constructor Details</h2>
533
-
534
- <div class="method_details first">
535
- <h3 class="signature first" id="initialize-instance_method">
536
-
537
- - (<tt>void</tt>) <strong>initialize</strong>(options, &amp;connect_blk)
538
-
539
-
540
-
541
-
542
-
543
- </h3><div class="docstring">
544
- <div class="discussion">
545
-
546
- <p>receives a list of options that are used to connect to the webserver and an
547
- actor to which the callbacks are delegated to</p>
548
-
549
- <pre class="code ruby"><code class="ruby">when receiving messages from a channel</code></pre>
550
-
551
-
552
- </div>
553
- </div>
554
- <div class="tags">
555
- <p class="tag_title">Parameters:</p>
556
- <ul class="param">
557
-
558
- <li>
559
-
560
- <span class='name'>options</span>
561
-
562
-
563
- <span class='type'>(<tt>Hash</tt>)</span>
564
-
565
-
566
-
567
- &mdash;
568
- <div class='inline'>
569
- <p>the options that can be used to connect to webser and send additional data</p>
570
- </div>
571
-
572
- </li>
573
-
574
- <li>
575
-
576
- <span class='name'>connect_blk</span>
577
-
578
-
579
- <span class='type'>(<tt>Proc</tt>)</span>
580
-
581
-
582
-
583
- &mdash;
584
- <div class='inline'>
585
- <p>Block that will execute after the connection is opened</p>
586
- </div>
587
-
588
- </li>
589
-
590
- </ul>
591
-
592
-
593
-
594
-
595
- <p class="tag_title">Options Hash (<tt>options</tt>):</p>
596
- <ul class="option">
597
-
598
- <li>
599
- <span class="name">:actor</span>
600
- <span class="type">(<tt>String</tt>)</span>
601
- <span class="default">
602
-
603
- </span>
604
-
605
- &mdash; <div class='inline'>
606
- <p>The actor that made the connection</p>
607
- </div>
608
-
609
- </li>
610
-
611
- <li>
612
- <span class="name">:hostname</span>
613
- <span class="type">(<tt>String</tt>)</span>
614
- <span class="default">
615
-
616
- </span>
617
-
618
- &mdash; <div class='inline'>
619
- <p>The hostname on which the webserver runs on</p>
620
- </div>
621
-
622
- </li>
623
-
624
- <li>
625
- <span class="name">:port</span>
626
- <span class="type">(<tt>String</tt>)</span>
627
- <span class="default">
628
-
629
- </span>
630
-
631
- &mdash; <div class='inline'>
632
- <p>The port on which the webserver runs on</p>
633
- </div>
634
-
635
- </li>
636
-
637
- <li>
638
- <span class="name">:path</span>
639
- <span class="type">(<tt>String</tt>)</span>
640
- <span class="default">
641
-
642
- </span>
643
-
644
- &mdash; <div class='inline'>
645
- <p>The request path that the webserver accepts</p>
646
- </div>
647
-
648
- </li>
649
-
650
- </ul>
651
-
652
-
653
-
654
-
655
-
656
- </div><table class="source_code">
657
- <tr>
658
- <td>
659
- <pre class="lines">
660
-
661
-
662
- 47
663
- 48
664
- 49
665
- 50
666
- 51
667
- 52</pre>
668
- </td>
669
- <td>
670
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 47</span>
671
-
672
- <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_connect_blk'>connect_blk</span><span class='rparen'>)</span>
673
- <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
674
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>: Please provide an actor in the options list!!!</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
675
- <span class='ivar'>@connect_blk</span> <span class='op'>=</span> <span class='id identifier rubyid_connect_blk'>connect_blk</span>
676
- <span class='ivar'>@client</span> <span class='op'>=</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>WebSocket</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ws://</span><span class='embexpr_beg'>#{</span><span class='ivar'>@hostname</span><span class='embexpr_end'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='ivar'>@port</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='rparen'>)</span>
677
- <span class='kw'>end</span></pre>
678
- </td>
679
- </tr>
680
- </table>
681
- </div>
682
-
683
- </div>
684
-
685
- <div id="instance_attr_details" class="attr_details">
686
- <h2>Instance Attribute Details</h2>
687
-
688
-
689
- <span id="actor=-instance_method"></span>
690
- <div class="method_details first">
691
- <h3 class="signature first" id="actor-instance_method">
692
-
693
- - (<tt>Celluloid::Actor</tt>) <strong>actor</strong>
694
-
695
-
696
-
697
-
698
-
699
- </h3><div class="docstring">
700
- <div class="discussion">
701
-
702
- <p>Returns actor to which callbacks will be delegated to</p>
703
-
704
-
705
- </div>
706
- </div>
707
- <div class="tags">
708
-
709
- <p class="tag_title">Returns:</p>
710
- <ul class="return">
711
-
712
- <li>
713
-
714
-
715
- <span class='type'>(<tt>Celluloid::Actor</tt>)</span>
716
-
717
-
718
-
719
- &mdash;
720
- <div class='inline'>
721
- <p>actor to which callbacks will be delegated to</p>
722
- </div>
723
-
724
- </li>
725
-
726
- </ul>
727
-
728
- </div><table class="source_code">
729
- <tr>
730
- <td>
731
- <pre class="lines">
732
-
733
-
734
- 28
735
- 29
736
- 30
737
- 31
738
- 32
739
- 33
740
- 34
741
- 35
742
- 36
743
- 37
744
- 38
745
- 39
746
- 40
747
- 41
748
- 42
749
- 43
750
- 44
751
- 45
752
- 46
753
- 47
754
- 48
755
- 49
756
- 50
757
- 51
758
- 52
759
- 53
760
- 54
761
- 55
762
- 56
763
- 57
764
- 58
765
- 59
766
- 60
767
- 61
768
- 62
769
- 63
770
- 64
771
- 65
772
- 66
773
- 67
774
- 68
775
- 69
776
- 70
777
- 71
778
- 72
779
- 73
780
- 74
781
- 75
782
- 76
783
- 77
784
- 78
785
- 79
786
- 80
787
- 81
788
- 82
789
- 83
790
- 84
791
- 85
792
- 86
793
- 87
794
- 88
795
- 89
796
- 90
797
- 91
798
- 92
799
- 93
800
- 94
801
- 95
802
- 96
803
- 97
804
- 98
805
- 99
806
- 100
807
- 101
808
- 102
809
- 103
810
- 104
811
- 105
812
- 106
813
- 107
814
- 108
815
- 109
816
- 110
817
- 111
818
- 112
819
- 113
820
- 114
821
- 115
822
- 116
823
- 117
824
- 118
825
- 119
826
- 120
827
- 121
828
- 122
829
- 123
830
- 124
831
- 125
832
- 126
833
- 127
834
- 128
835
- 129
836
- 130
837
- 131
838
- 132
839
- 133
840
- 134
841
- 135
842
- 136
843
- 137
844
- 138
845
- 139
846
- 140
847
- 141
848
- 142
849
- 143
850
- 144
851
- 145
852
- 146
853
- 147
854
- 148
855
- 149
856
- 150
857
- 151
858
- 152
859
- 153
860
- 154
861
- 155
862
- 156
863
- 157
864
- 158
865
- 159
866
- 160
867
- 161
868
- 162
869
- 163
870
- 164
871
- 165
872
- 166
873
- 167
874
- 168
875
- 169
876
- 170
877
- 171
878
- 172
879
- 173
880
- 174
881
- 175
882
- 176</pre>
883
- </td>
884
- <td>
885
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 28</span>
886
-
887
- <span class='kw'>class</span> <span class='const'>PubSubWorker</span>
888
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span>
889
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>Logger</span>
890
- <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:actor</span><span class='comma'>,</span> <span class='symbol'>:connect_blk</span><span class='comma'>,</span> <span class='symbol'>:client</span><span class='comma'>,</span> <span class='symbol'>:options</span><span class='comma'>,</span> <span class='symbol'>:hostname</span><span class='comma'>,</span> <span class='symbol'>:port</span><span class='comma'>,</span> <span class='symbol'>:path</span>
891
-
892
- <span class='comment'># receives a list of options that are used to connect to the webserver and an actor to which the callbacks are delegated to
893
- </span> <span class='comment'># when receiving messages from a channel
894
- </span> <span class='comment'>#
895
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
896
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
897
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
898
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
899
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
900
- </span> <span class='comment'>#
901
- </span> <span class='comment'># @param [Proc] connect_blk Block that will execute after the connection is opened
902
- </span> <span class='comment'>#
903
- </span> <span class='comment'># @return [void]
904
- </span> <span class='comment'>#
905
- </span> <span class='comment'># @api public
906
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_connect_blk'>connect_blk</span><span class='rparen'>)</span>
907
- <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
908
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>: Please provide an actor in the options list!!!</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
909
- <span class='ivar'>@connect_blk</span> <span class='op'>=</span> <span class='id identifier rubyid_connect_blk'>connect_blk</span>
910
- <span class='ivar'>@client</span> <span class='op'>=</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>WebSocket</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ws://</span><span class='embexpr_beg'>#{</span><span class='ivar'>@hostname</span><span class='embexpr_end'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='ivar'>@port</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='rparen'>)</span>
911
- <span class='kw'>end</span>
912
-
913
- <span class='comment'># check the options list for values and sets default values if not found
914
- </span> <span class='comment'>#
915
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
916
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
917
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
918
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
919
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
920
- </span> <span class='comment'>#
921
- </span> <span class='comment'># @return [void]
922
- </span> <span class='comment'>#
923
- </span> <span class='comment'># @api public
924
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
925
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Options is not a hash</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
926
- <span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys!'>stringify_keys!</span>
927
- <span class='ivar'>@actor</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>actor</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span>
928
- <span class='ivar'>@hostname</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>hostname</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>HOST</span><span class='rparen'>)</span>
929
- <span class='ivar'>@port</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>port</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PORT</span><span class='rparen'>)</span>
930
- <span class='ivar'>@path</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>path</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PATH</span><span class='rparen'>)</span>
931
- <span class='kw'>end</span>
932
-
933
- <span class='comment'># checks if debug is enabled
934
- </span> <span class='comment'>#
935
- </span> <span class='comment'>#
936
- </span> <span class='comment'># @return [boolean]
937
- </span> <span class='comment'>#
938
- </span> <span class='comment'># @api public
939
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
940
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
941
- <span class='kw'>end</span>
942
-
943
- <span class='comment'># subscribes to a channel . need to be used inside the connect block passed to the actor
944
- </span> <span class='comment'>#
945
- </span> <span class='comment'># @param [string] channel
946
- </span> <span class='comment'>#
947
- </span> <span class='comment'># @return [void]
948
- </span> <span class='comment'>#
949
- </span> <span class='comment'># @api public
950
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_subscribe'>subscribe</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
951
- <span class='id identifier rubyid_subscription_data'>subscription_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='rbrace'>}</span>
952
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> tries to subscribe </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
953
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='rparen'>)</span>
954
- <span class='kw'>end</span>
955
-
956
- <span class='comment'># publishes to a channel some data (can be anything)
957
- </span> <span class='comment'>#
958
- </span> <span class='comment'># @param [string] channel
959
- </span> <span class='comment'># @param [#to_s] data
960
- </span> <span class='comment'>#
961
- </span> <span class='comment'># @return [void]
962
- </span> <span class='comment'>#
963
- </span> <span class='comment'># @api public
964
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_publish'>publish</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
965
- <span class='id identifier rubyid_publishing_data'>publishing_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_data'>data</span> <span class='rbrace'>}</span>
966
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> publishl to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> message: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
967
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='rparen'>)</span>
968
- <span class='kw'>end</span>
969
-
970
- <span class='comment'># callback executes after connection is opened and delegates action to actor
971
- </span> <span class='comment'>#
972
- </span> <span class='comment'># @return [void]
973
- </span> <span class='comment'>#
974
- </span> <span class='comment'># @api public
975
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_open'>on_open</span>
976
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> websocket connection opened</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
977
- <span class='ivar'>@connect_blk</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
978
- <span class='kw'>end</span>
979
-
980
- <span class='comment'># callback executes when actor receives a message from a subscribed channel
981
- </span> <span class='comment'># and parses the message using JSON.parse and dispatches the parsed
982
- </span> <span class='comment'># message to the original actor that made the connection
983
- </span> <span class='comment'>#
984
- </span> <span class='comment'># @param [JSON] data
985
- </span> <span class='comment'>#
986
- </span> <span class='comment'># @return [void]
987
- </span> <span class='comment'>#
988
- </span> <span class='comment'># @api public
989
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
990
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received plain </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_data'>data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
991
- <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
992
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
993
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
994
- <span class='kw'>end</span>
995
-
996
- <span class='comment'># callback executes when connection closes
997
- </span> <span class='comment'>#
998
- </span> <span class='comment'># @param [String] code
999
- </span> <span class='comment'>#
1000
- </span> <span class='comment'># @param [String] reason
1001
- </span> <span class='comment'>#
1002
- </span> <span class='comment'># @return [void]
1003
- </span> <span class='comment'>#
1004
- </span> <span class='comment'># @api public
1005
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
1006
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_terminate'>terminate</span>
1007
- <span class='id identifier rubyid_terminate'>terminate</span>
1008
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> dispatching on close </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_code'>code</span><span class='embexpr_end'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_reason'>reason</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1009
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
1010
- <span class='kw'>end</span>
1011
-
1012
- <span class='id identifier rubyid_private'>private</span>
1013
-
1014
- <span class='comment'># method used to send messages to the webserver
1015
- </span> <span class='comment'># checks too see if the message is a hash and if it is it will transform it to JSON and send it to the webser
1016
- </span> <span class='comment'># otherwise will construct a JSON object that will have the key action with the value &#39;message&quot; and the key message witth the parameter&#39;s value
1017
- </span> <span class='comment'>#
1018
- </span> <span class='comment'># @param [Hash] message
1019
- </span> <span class='comment'>#
1020
- </span> <span class='comment'># @return [void]
1021
- </span> <span class='comment'>#
1022
- </span> <span class='comment'># @api private
1023
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1024
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='kw'>nil</span>
1025
- <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
1026
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1027
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
1028
- <span class='kw'>else</span>
1029
- <span class='id identifier rubyid_text_messsage'>text_messsage</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='label'>action:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>message</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1030
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_text_messsage'>text_messsage</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1031
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_text_messsage'>text_messsage</span>
1032
- <span class='kw'>end</span>
1033
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_text'>text</span> <span class='id identifier rubyid_final_message'>final_message</span>
1034
- <span class='kw'>end</span>
1035
- <span class='kw'>end</span></pre>
1036
- </td>
1037
- </tr>
1038
- </table>
1039
- </div>
1040
-
1041
-
1042
- <span id="client=-instance_method"></span>
1043
- <div class="method_details ">
1044
- <h3 class="signature " id="client-instance_method">
1045
-
1046
- - (<tt>Celluloid::WebSocket::Client</tt>) <strong>client</strong>
1047
-
1048
-
1049
-
1050
-
1051
-
1052
- </h3><div class="docstring">
1053
- <div class="discussion">
1054
-
1055
- <p>Returns A websocket client that is used to chat witht the webserver</p>
1056
-
1057
-
1058
- </div>
1059
- </div>
1060
- <div class="tags">
1061
-
1062
- <p class="tag_title">Returns:</p>
1063
- <ul class="return">
1064
-
1065
- <li>
1066
-
1067
-
1068
- <span class='type'>(<tt>Celluloid::WebSocket::Client</tt>)</span>
1069
-
1070
-
1071
-
1072
- &mdash;
1073
- <div class='inline'>
1074
- <p>A websocket client that is used to chat witht the webserver</p>
1075
- </div>
1076
-
1077
- </li>
1078
-
1079
- </ul>
1080
-
1081
- </div><table class="source_code">
1082
- <tr>
1083
- <td>
1084
- <pre class="lines">
1085
-
1086
-
1087
- 28
1088
- 29
1089
- 30
1090
- 31
1091
- 32
1092
- 33
1093
- 34
1094
- 35
1095
- 36
1096
- 37
1097
- 38
1098
- 39
1099
- 40
1100
- 41
1101
- 42
1102
- 43
1103
- 44
1104
- 45
1105
- 46
1106
- 47
1107
- 48
1108
- 49
1109
- 50
1110
- 51
1111
- 52
1112
- 53
1113
- 54
1114
- 55
1115
- 56
1116
- 57
1117
- 58
1118
- 59
1119
- 60
1120
- 61
1121
- 62
1122
- 63
1123
- 64
1124
- 65
1125
- 66
1126
- 67
1127
- 68
1128
- 69
1129
- 70
1130
- 71
1131
- 72
1132
- 73
1133
- 74
1134
- 75
1135
- 76
1136
- 77
1137
- 78
1138
- 79
1139
- 80
1140
- 81
1141
- 82
1142
- 83
1143
- 84
1144
- 85
1145
- 86
1146
- 87
1147
- 88
1148
- 89
1149
- 90
1150
- 91
1151
- 92
1152
- 93
1153
- 94
1154
- 95
1155
- 96
1156
- 97
1157
- 98
1158
- 99
1159
- 100
1160
- 101
1161
- 102
1162
- 103
1163
- 104
1164
- 105
1165
- 106
1166
- 107
1167
- 108
1168
- 109
1169
- 110
1170
- 111
1171
- 112
1172
- 113
1173
- 114
1174
- 115
1175
- 116
1176
- 117
1177
- 118
1178
- 119
1179
- 120
1180
- 121
1181
- 122
1182
- 123
1183
- 124
1184
- 125
1185
- 126
1186
- 127
1187
- 128
1188
- 129
1189
- 130
1190
- 131
1191
- 132
1192
- 133
1193
- 134
1194
- 135
1195
- 136
1196
- 137
1197
- 138
1198
- 139
1199
- 140
1200
- 141
1201
- 142
1202
- 143
1203
- 144
1204
- 145
1205
- 146
1206
- 147
1207
- 148
1208
- 149
1209
- 150
1210
- 151
1211
- 152
1212
- 153
1213
- 154
1214
- 155
1215
- 156
1216
- 157
1217
- 158
1218
- 159
1219
- 160
1220
- 161
1221
- 162
1222
- 163
1223
- 164
1224
- 165
1225
- 166
1226
- 167
1227
- 168
1228
- 169
1229
- 170
1230
- 171
1231
- 172
1232
- 173
1233
- 174
1234
- 175
1235
- 176</pre>
1236
- </td>
1237
- <td>
1238
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 28</span>
1239
-
1240
- <span class='kw'>class</span> <span class='const'>PubSubWorker</span>
1241
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span>
1242
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>Logger</span>
1243
- <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:actor</span><span class='comma'>,</span> <span class='symbol'>:connect_blk</span><span class='comma'>,</span> <span class='symbol'>:client</span><span class='comma'>,</span> <span class='symbol'>:options</span><span class='comma'>,</span> <span class='symbol'>:hostname</span><span class='comma'>,</span> <span class='symbol'>:port</span><span class='comma'>,</span> <span class='symbol'>:path</span>
1244
-
1245
- <span class='comment'># receives a list of options that are used to connect to the webserver and an actor to which the callbacks are delegated to
1246
- </span> <span class='comment'># when receiving messages from a channel
1247
- </span> <span class='comment'>#
1248
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
1249
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
1250
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
1251
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
1252
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
1253
- </span> <span class='comment'>#
1254
- </span> <span class='comment'># @param [Proc] connect_blk Block that will execute after the connection is opened
1255
- </span> <span class='comment'>#
1256
- </span> <span class='comment'># @return [void]
1257
- </span> <span class='comment'>#
1258
- </span> <span class='comment'># @api public
1259
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_connect_blk'>connect_blk</span><span class='rparen'>)</span>
1260
- <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
1261
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>: Please provide an actor in the options list!!!</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
1262
- <span class='ivar'>@connect_blk</span> <span class='op'>=</span> <span class='id identifier rubyid_connect_blk'>connect_blk</span>
1263
- <span class='ivar'>@client</span> <span class='op'>=</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>WebSocket</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ws://</span><span class='embexpr_beg'>#{</span><span class='ivar'>@hostname</span><span class='embexpr_end'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='ivar'>@port</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='rparen'>)</span>
1264
- <span class='kw'>end</span>
1265
-
1266
- <span class='comment'># check the options list for values and sets default values if not found
1267
- </span> <span class='comment'>#
1268
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
1269
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
1270
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
1271
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
1272
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
1273
- </span> <span class='comment'>#
1274
- </span> <span class='comment'># @return [void]
1275
- </span> <span class='comment'>#
1276
- </span> <span class='comment'># @api public
1277
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
1278
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Options is not a hash</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
1279
- <span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys!'>stringify_keys!</span>
1280
- <span class='ivar'>@actor</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>actor</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span>
1281
- <span class='ivar'>@hostname</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>hostname</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>HOST</span><span class='rparen'>)</span>
1282
- <span class='ivar'>@port</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>port</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PORT</span><span class='rparen'>)</span>
1283
- <span class='ivar'>@path</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>path</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PATH</span><span class='rparen'>)</span>
1284
- <span class='kw'>end</span>
1285
-
1286
- <span class='comment'># checks if debug is enabled
1287
- </span> <span class='comment'>#
1288
- </span> <span class='comment'>#
1289
- </span> <span class='comment'># @return [boolean]
1290
- </span> <span class='comment'>#
1291
- </span> <span class='comment'># @api public
1292
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1293
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1294
- <span class='kw'>end</span>
1295
-
1296
- <span class='comment'># subscribes to a channel . need to be used inside the connect block passed to the actor
1297
- </span> <span class='comment'>#
1298
- </span> <span class='comment'># @param [string] channel
1299
- </span> <span class='comment'>#
1300
- </span> <span class='comment'># @return [void]
1301
- </span> <span class='comment'>#
1302
- </span> <span class='comment'># @api public
1303
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_subscribe'>subscribe</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
1304
- <span class='id identifier rubyid_subscription_data'>subscription_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='rbrace'>}</span>
1305
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> tries to subscribe </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1306
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='rparen'>)</span>
1307
- <span class='kw'>end</span>
1308
-
1309
- <span class='comment'># publishes to a channel some data (can be anything)
1310
- </span> <span class='comment'>#
1311
- </span> <span class='comment'># @param [string] channel
1312
- </span> <span class='comment'># @param [#to_s] data
1313
- </span> <span class='comment'>#
1314
- </span> <span class='comment'># @return [void]
1315
- </span> <span class='comment'>#
1316
- </span> <span class='comment'># @api public
1317
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_publish'>publish</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
1318
- <span class='id identifier rubyid_publishing_data'>publishing_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_data'>data</span> <span class='rbrace'>}</span>
1319
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> publishl to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> message: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1320
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='rparen'>)</span>
1321
- <span class='kw'>end</span>
1322
-
1323
- <span class='comment'># callback executes after connection is opened and delegates action to actor
1324
- </span> <span class='comment'>#
1325
- </span> <span class='comment'># @return [void]
1326
- </span> <span class='comment'>#
1327
- </span> <span class='comment'># @api public
1328
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_open'>on_open</span>
1329
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> websocket connection opened</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1330
- <span class='ivar'>@connect_blk</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
1331
- <span class='kw'>end</span>
1332
-
1333
- <span class='comment'># callback executes when actor receives a message from a subscribed channel
1334
- </span> <span class='comment'># and parses the message using JSON.parse and dispatches the parsed
1335
- </span> <span class='comment'># message to the original actor that made the connection
1336
- </span> <span class='comment'>#
1337
- </span> <span class='comment'># @param [JSON] data
1338
- </span> <span class='comment'>#
1339
- </span> <span class='comment'># @return [void]
1340
- </span> <span class='comment'>#
1341
- </span> <span class='comment'># @api public
1342
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
1343
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received plain </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_data'>data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1344
- <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
1345
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1346
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1347
- <span class='kw'>end</span>
1348
-
1349
- <span class='comment'># callback executes when connection closes
1350
- </span> <span class='comment'>#
1351
- </span> <span class='comment'># @param [String] code
1352
- </span> <span class='comment'>#
1353
- </span> <span class='comment'># @param [String] reason
1354
- </span> <span class='comment'>#
1355
- </span> <span class='comment'># @return [void]
1356
- </span> <span class='comment'>#
1357
- </span> <span class='comment'># @api public
1358
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
1359
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_terminate'>terminate</span>
1360
- <span class='id identifier rubyid_terminate'>terminate</span>
1361
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> dispatching on close </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_code'>code</span><span class='embexpr_end'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_reason'>reason</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1362
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
1363
- <span class='kw'>end</span>
1364
-
1365
- <span class='id identifier rubyid_private'>private</span>
1366
-
1367
- <span class='comment'># method used to send messages to the webserver
1368
- </span> <span class='comment'># checks too see if the message is a hash and if it is it will transform it to JSON and send it to the webser
1369
- </span> <span class='comment'># otherwise will construct a JSON object that will have the key action with the value &#39;message&quot; and the key message witth the parameter&#39;s value
1370
- </span> <span class='comment'>#
1371
- </span> <span class='comment'># @param [Hash] message
1372
- </span> <span class='comment'>#
1373
- </span> <span class='comment'># @return [void]
1374
- </span> <span class='comment'>#
1375
- </span> <span class='comment'># @api private
1376
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1377
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='kw'>nil</span>
1378
- <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
1379
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1380
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
1381
- <span class='kw'>else</span>
1382
- <span class='id identifier rubyid_text_messsage'>text_messsage</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='label'>action:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>message</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1383
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_text_messsage'>text_messsage</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1384
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_text_messsage'>text_messsage</span>
1385
- <span class='kw'>end</span>
1386
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_text'>text</span> <span class='id identifier rubyid_final_message'>final_message</span>
1387
- <span class='kw'>end</span>
1388
- <span class='kw'>end</span></pre>
1389
- </td>
1390
- </tr>
1391
- </table>
1392
- </div>
1393
-
1394
-
1395
- <span id="connect_blk=-instance_method"></span>
1396
- <div class="method_details ">
1397
- <h3 class="signature " id="connect_blk-instance_method">
1398
-
1399
- - (<tt>Proc</tt>) <strong>connect_blk</strong>
1400
-
1401
-
1402
-
1403
-
1404
-
1405
- </h3><div class="docstring">
1406
- <div class="discussion">
1407
-
1408
- <p>Returns Block that will execute after the connection is opened</p>
1409
-
1410
-
1411
- </div>
1412
- </div>
1413
- <div class="tags">
1414
-
1415
- <p class="tag_title">Returns:</p>
1416
- <ul class="return">
1417
-
1418
- <li>
1419
-
1420
-
1421
- <span class='type'>(<tt>Proc</tt>)</span>
1422
-
1423
-
1424
-
1425
- &mdash;
1426
- <div class='inline'>
1427
- <p>Block that will execute after the connection is opened</p>
1428
- </div>
1429
-
1430
- </li>
1431
-
1432
- </ul>
1433
-
1434
- </div><table class="source_code">
1435
- <tr>
1436
- <td>
1437
- <pre class="lines">
1438
-
1439
-
1440
- 28
1441
- 29
1442
- 30
1443
- 31
1444
- 32
1445
- 33
1446
- 34
1447
- 35
1448
- 36
1449
- 37
1450
- 38
1451
- 39
1452
- 40
1453
- 41
1454
- 42
1455
- 43
1456
- 44
1457
- 45
1458
- 46
1459
- 47
1460
- 48
1461
- 49
1462
- 50
1463
- 51
1464
- 52
1465
- 53
1466
- 54
1467
- 55
1468
- 56
1469
- 57
1470
- 58
1471
- 59
1472
- 60
1473
- 61
1474
- 62
1475
- 63
1476
- 64
1477
- 65
1478
- 66
1479
- 67
1480
- 68
1481
- 69
1482
- 70
1483
- 71
1484
- 72
1485
- 73
1486
- 74
1487
- 75
1488
- 76
1489
- 77
1490
- 78
1491
- 79
1492
- 80
1493
- 81
1494
- 82
1495
- 83
1496
- 84
1497
- 85
1498
- 86
1499
- 87
1500
- 88
1501
- 89
1502
- 90
1503
- 91
1504
- 92
1505
- 93
1506
- 94
1507
- 95
1508
- 96
1509
- 97
1510
- 98
1511
- 99
1512
- 100
1513
- 101
1514
- 102
1515
- 103
1516
- 104
1517
- 105
1518
- 106
1519
- 107
1520
- 108
1521
- 109
1522
- 110
1523
- 111
1524
- 112
1525
- 113
1526
- 114
1527
- 115
1528
- 116
1529
- 117
1530
- 118
1531
- 119
1532
- 120
1533
- 121
1534
- 122
1535
- 123
1536
- 124
1537
- 125
1538
- 126
1539
- 127
1540
- 128
1541
- 129
1542
- 130
1543
- 131
1544
- 132
1545
- 133
1546
- 134
1547
- 135
1548
- 136
1549
- 137
1550
- 138
1551
- 139
1552
- 140
1553
- 141
1554
- 142
1555
- 143
1556
- 144
1557
- 145
1558
- 146
1559
- 147
1560
- 148
1561
- 149
1562
- 150
1563
- 151
1564
- 152
1565
- 153
1566
- 154
1567
- 155
1568
- 156
1569
- 157
1570
- 158
1571
- 159
1572
- 160
1573
- 161
1574
- 162
1575
- 163
1576
- 164
1577
- 165
1578
- 166
1579
- 167
1580
- 168
1581
- 169
1582
- 170
1583
- 171
1584
- 172
1585
- 173
1586
- 174
1587
- 175
1588
- 176</pre>
1589
- </td>
1590
- <td>
1591
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 28</span>
1592
-
1593
- <span class='kw'>class</span> <span class='const'>PubSubWorker</span>
1594
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span>
1595
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>Logger</span>
1596
- <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:actor</span><span class='comma'>,</span> <span class='symbol'>:connect_blk</span><span class='comma'>,</span> <span class='symbol'>:client</span><span class='comma'>,</span> <span class='symbol'>:options</span><span class='comma'>,</span> <span class='symbol'>:hostname</span><span class='comma'>,</span> <span class='symbol'>:port</span><span class='comma'>,</span> <span class='symbol'>:path</span>
1597
-
1598
- <span class='comment'># receives a list of options that are used to connect to the webserver and an actor to which the callbacks are delegated to
1599
- </span> <span class='comment'># when receiving messages from a channel
1600
- </span> <span class='comment'>#
1601
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
1602
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
1603
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
1604
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
1605
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
1606
- </span> <span class='comment'>#
1607
- </span> <span class='comment'># @param [Proc] connect_blk Block that will execute after the connection is opened
1608
- </span> <span class='comment'>#
1609
- </span> <span class='comment'># @return [void]
1610
- </span> <span class='comment'>#
1611
- </span> <span class='comment'># @api public
1612
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_connect_blk'>connect_blk</span><span class='rparen'>)</span>
1613
- <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
1614
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>: Please provide an actor in the options list!!!</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
1615
- <span class='ivar'>@connect_blk</span> <span class='op'>=</span> <span class='id identifier rubyid_connect_blk'>connect_blk</span>
1616
- <span class='ivar'>@client</span> <span class='op'>=</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>WebSocket</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ws://</span><span class='embexpr_beg'>#{</span><span class='ivar'>@hostname</span><span class='embexpr_end'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='ivar'>@port</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='rparen'>)</span>
1617
- <span class='kw'>end</span>
1618
-
1619
- <span class='comment'># check the options list for values and sets default values if not found
1620
- </span> <span class='comment'>#
1621
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
1622
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
1623
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
1624
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
1625
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
1626
- </span> <span class='comment'>#
1627
- </span> <span class='comment'># @return [void]
1628
- </span> <span class='comment'>#
1629
- </span> <span class='comment'># @api public
1630
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
1631
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Options is not a hash</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
1632
- <span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys!'>stringify_keys!</span>
1633
- <span class='ivar'>@actor</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>actor</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span>
1634
- <span class='ivar'>@hostname</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>hostname</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>HOST</span><span class='rparen'>)</span>
1635
- <span class='ivar'>@port</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>port</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PORT</span><span class='rparen'>)</span>
1636
- <span class='ivar'>@path</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>path</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PATH</span><span class='rparen'>)</span>
1637
- <span class='kw'>end</span>
1638
-
1639
- <span class='comment'># checks if debug is enabled
1640
- </span> <span class='comment'>#
1641
- </span> <span class='comment'>#
1642
- </span> <span class='comment'># @return [boolean]
1643
- </span> <span class='comment'>#
1644
- </span> <span class='comment'># @api public
1645
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1646
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1647
- <span class='kw'>end</span>
1648
-
1649
- <span class='comment'># subscribes to a channel . need to be used inside the connect block passed to the actor
1650
- </span> <span class='comment'>#
1651
- </span> <span class='comment'># @param [string] channel
1652
- </span> <span class='comment'>#
1653
- </span> <span class='comment'># @return [void]
1654
- </span> <span class='comment'>#
1655
- </span> <span class='comment'># @api public
1656
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_subscribe'>subscribe</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
1657
- <span class='id identifier rubyid_subscription_data'>subscription_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='rbrace'>}</span>
1658
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> tries to subscribe </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1659
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='rparen'>)</span>
1660
- <span class='kw'>end</span>
1661
-
1662
- <span class='comment'># publishes to a channel some data (can be anything)
1663
- </span> <span class='comment'>#
1664
- </span> <span class='comment'># @param [string] channel
1665
- </span> <span class='comment'># @param [#to_s] data
1666
- </span> <span class='comment'>#
1667
- </span> <span class='comment'># @return [void]
1668
- </span> <span class='comment'>#
1669
- </span> <span class='comment'># @api public
1670
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_publish'>publish</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
1671
- <span class='id identifier rubyid_publishing_data'>publishing_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_data'>data</span> <span class='rbrace'>}</span>
1672
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> publishl to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> message: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1673
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='rparen'>)</span>
1674
- <span class='kw'>end</span>
1675
-
1676
- <span class='comment'># callback executes after connection is opened and delegates action to actor
1677
- </span> <span class='comment'>#
1678
- </span> <span class='comment'># @return [void]
1679
- </span> <span class='comment'>#
1680
- </span> <span class='comment'># @api public
1681
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_open'>on_open</span>
1682
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> websocket connection opened</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1683
- <span class='ivar'>@connect_blk</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
1684
- <span class='kw'>end</span>
1685
-
1686
- <span class='comment'># callback executes when actor receives a message from a subscribed channel
1687
- </span> <span class='comment'># and parses the message using JSON.parse and dispatches the parsed
1688
- </span> <span class='comment'># message to the original actor that made the connection
1689
- </span> <span class='comment'>#
1690
- </span> <span class='comment'># @param [JSON] data
1691
- </span> <span class='comment'>#
1692
- </span> <span class='comment'># @return [void]
1693
- </span> <span class='comment'>#
1694
- </span> <span class='comment'># @api public
1695
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
1696
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received plain </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_data'>data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1697
- <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
1698
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1699
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1700
- <span class='kw'>end</span>
1701
-
1702
- <span class='comment'># callback executes when connection closes
1703
- </span> <span class='comment'>#
1704
- </span> <span class='comment'># @param [String] code
1705
- </span> <span class='comment'>#
1706
- </span> <span class='comment'># @param [String] reason
1707
- </span> <span class='comment'>#
1708
- </span> <span class='comment'># @return [void]
1709
- </span> <span class='comment'>#
1710
- </span> <span class='comment'># @api public
1711
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
1712
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_terminate'>terminate</span>
1713
- <span class='id identifier rubyid_terminate'>terminate</span>
1714
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> dispatching on close </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_code'>code</span><span class='embexpr_end'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_reason'>reason</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1715
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
1716
- <span class='kw'>end</span>
1717
-
1718
- <span class='id identifier rubyid_private'>private</span>
1719
-
1720
- <span class='comment'># method used to send messages to the webserver
1721
- </span> <span class='comment'># checks too see if the message is a hash and if it is it will transform it to JSON and send it to the webser
1722
- </span> <span class='comment'># otherwise will construct a JSON object that will have the key action with the value &#39;message&quot; and the key message witth the parameter&#39;s value
1723
- </span> <span class='comment'>#
1724
- </span> <span class='comment'># @param [Hash] message
1725
- </span> <span class='comment'>#
1726
- </span> <span class='comment'># @return [void]
1727
- </span> <span class='comment'>#
1728
- </span> <span class='comment'># @api private
1729
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1730
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='kw'>nil</span>
1731
- <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
1732
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1733
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
1734
- <span class='kw'>else</span>
1735
- <span class='id identifier rubyid_text_messsage'>text_messsage</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='label'>action:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>message</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
1736
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_text_messsage'>text_messsage</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1737
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_text_messsage'>text_messsage</span>
1738
- <span class='kw'>end</span>
1739
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_text'>text</span> <span class='id identifier rubyid_final_message'>final_message</span>
1740
- <span class='kw'>end</span>
1741
- <span class='kw'>end</span></pre>
1742
- </td>
1743
- </tr>
1744
- </table>
1745
- </div>
1746
-
1747
-
1748
- <span id="hostname=-instance_method"></span>
1749
- <div class="method_details ">
1750
- <h3 class="signature " id="hostname-instance_method">
1751
-
1752
- - (<tt>String</tt>) <strong>hostname</strong>
1753
-
1754
-
1755
-
1756
-
1757
-
1758
- </h3><div class="docstring">
1759
- <div class="discussion">
1760
-
1761
- <p>Returns The hostname on which the webserver runs on</p>
1762
-
1763
-
1764
- </div>
1765
- </div>
1766
- <div class="tags">
1767
-
1768
- <p class="tag_title">Returns:</p>
1769
- <ul class="return">
1770
-
1771
- <li>
1772
-
1773
-
1774
- <span class='type'>(<tt>String</tt>)</span>
1775
-
1776
-
1777
-
1778
- &mdash;
1779
- <div class='inline'>
1780
- <p>The hostname on which the webserver runs on</p>
1781
- </div>
1782
-
1783
- </li>
1784
-
1785
- </ul>
1786
-
1787
- </div><table class="source_code">
1788
- <tr>
1789
- <td>
1790
- <pre class="lines">
1791
-
1792
-
1793
- 28
1794
- 29
1795
- 30
1796
- 31
1797
- 32
1798
- 33
1799
- 34
1800
- 35
1801
- 36
1802
- 37
1803
- 38
1804
- 39
1805
- 40
1806
- 41
1807
- 42
1808
- 43
1809
- 44
1810
- 45
1811
- 46
1812
- 47
1813
- 48
1814
- 49
1815
- 50
1816
- 51
1817
- 52
1818
- 53
1819
- 54
1820
- 55
1821
- 56
1822
- 57
1823
- 58
1824
- 59
1825
- 60
1826
- 61
1827
- 62
1828
- 63
1829
- 64
1830
- 65
1831
- 66
1832
- 67
1833
- 68
1834
- 69
1835
- 70
1836
- 71
1837
- 72
1838
- 73
1839
- 74
1840
- 75
1841
- 76
1842
- 77
1843
- 78
1844
- 79
1845
- 80
1846
- 81
1847
- 82
1848
- 83
1849
- 84
1850
- 85
1851
- 86
1852
- 87
1853
- 88
1854
- 89
1855
- 90
1856
- 91
1857
- 92
1858
- 93
1859
- 94
1860
- 95
1861
- 96
1862
- 97
1863
- 98
1864
- 99
1865
- 100
1866
- 101
1867
- 102
1868
- 103
1869
- 104
1870
- 105
1871
- 106
1872
- 107
1873
- 108
1874
- 109
1875
- 110
1876
- 111
1877
- 112
1878
- 113
1879
- 114
1880
- 115
1881
- 116
1882
- 117
1883
- 118
1884
- 119
1885
- 120
1886
- 121
1887
- 122
1888
- 123
1889
- 124
1890
- 125
1891
- 126
1892
- 127
1893
- 128
1894
- 129
1895
- 130
1896
- 131
1897
- 132
1898
- 133
1899
- 134
1900
- 135
1901
- 136
1902
- 137
1903
- 138
1904
- 139
1905
- 140
1906
- 141
1907
- 142
1908
- 143
1909
- 144
1910
- 145
1911
- 146
1912
- 147
1913
- 148
1914
- 149
1915
- 150
1916
- 151
1917
- 152
1918
- 153
1919
- 154
1920
- 155
1921
- 156
1922
- 157
1923
- 158
1924
- 159
1925
- 160
1926
- 161
1927
- 162
1928
- 163
1929
- 164
1930
- 165
1931
- 166
1932
- 167
1933
- 168
1934
- 169
1935
- 170
1936
- 171
1937
- 172
1938
- 173
1939
- 174
1940
- 175
1941
- 176</pre>
1942
- </td>
1943
- <td>
1944
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 28</span>
1945
-
1946
- <span class='kw'>class</span> <span class='const'>PubSubWorker</span>
1947
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span>
1948
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>Logger</span>
1949
- <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:actor</span><span class='comma'>,</span> <span class='symbol'>:connect_blk</span><span class='comma'>,</span> <span class='symbol'>:client</span><span class='comma'>,</span> <span class='symbol'>:options</span><span class='comma'>,</span> <span class='symbol'>:hostname</span><span class='comma'>,</span> <span class='symbol'>:port</span><span class='comma'>,</span> <span class='symbol'>:path</span>
1950
-
1951
- <span class='comment'># receives a list of options that are used to connect to the webserver and an actor to which the callbacks are delegated to
1952
- </span> <span class='comment'># when receiving messages from a channel
1953
- </span> <span class='comment'>#
1954
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
1955
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
1956
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
1957
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
1958
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
1959
- </span> <span class='comment'>#
1960
- </span> <span class='comment'># @param [Proc] connect_blk Block that will execute after the connection is opened
1961
- </span> <span class='comment'>#
1962
- </span> <span class='comment'># @return [void]
1963
- </span> <span class='comment'>#
1964
- </span> <span class='comment'># @api public
1965
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_connect_blk'>connect_blk</span><span class='rparen'>)</span>
1966
- <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
1967
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>: Please provide an actor in the options list!!!</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
1968
- <span class='ivar'>@connect_blk</span> <span class='op'>=</span> <span class='id identifier rubyid_connect_blk'>connect_blk</span>
1969
- <span class='ivar'>@client</span> <span class='op'>=</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>WebSocket</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ws://</span><span class='embexpr_beg'>#{</span><span class='ivar'>@hostname</span><span class='embexpr_end'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='ivar'>@port</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='rparen'>)</span>
1970
- <span class='kw'>end</span>
1971
-
1972
- <span class='comment'># check the options list for values and sets default values if not found
1973
- </span> <span class='comment'>#
1974
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
1975
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
1976
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
1977
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
1978
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
1979
- </span> <span class='comment'>#
1980
- </span> <span class='comment'># @return [void]
1981
- </span> <span class='comment'>#
1982
- </span> <span class='comment'># @api public
1983
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
1984
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Options is not a hash</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
1985
- <span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys!'>stringify_keys!</span>
1986
- <span class='ivar'>@actor</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>actor</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span>
1987
- <span class='ivar'>@hostname</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>hostname</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>HOST</span><span class='rparen'>)</span>
1988
- <span class='ivar'>@port</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>port</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PORT</span><span class='rparen'>)</span>
1989
- <span class='ivar'>@path</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>path</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PATH</span><span class='rparen'>)</span>
1990
- <span class='kw'>end</span>
1991
-
1992
- <span class='comment'># checks if debug is enabled
1993
- </span> <span class='comment'>#
1994
- </span> <span class='comment'>#
1995
- </span> <span class='comment'># @return [boolean]
1996
- </span> <span class='comment'>#
1997
- </span> <span class='comment'># @api public
1998
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
1999
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2000
- <span class='kw'>end</span>
2001
-
2002
- <span class='comment'># subscribes to a channel . need to be used inside the connect block passed to the actor
2003
- </span> <span class='comment'>#
2004
- </span> <span class='comment'># @param [string] channel
2005
- </span> <span class='comment'>#
2006
- </span> <span class='comment'># @return [void]
2007
- </span> <span class='comment'>#
2008
- </span> <span class='comment'># @api public
2009
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_subscribe'>subscribe</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
2010
- <span class='id identifier rubyid_subscription_data'>subscription_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='rbrace'>}</span>
2011
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> tries to subscribe </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2012
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='rparen'>)</span>
2013
- <span class='kw'>end</span>
2014
-
2015
- <span class='comment'># publishes to a channel some data (can be anything)
2016
- </span> <span class='comment'>#
2017
- </span> <span class='comment'># @param [string] channel
2018
- </span> <span class='comment'># @param [#to_s] data
2019
- </span> <span class='comment'>#
2020
- </span> <span class='comment'># @return [void]
2021
- </span> <span class='comment'>#
2022
- </span> <span class='comment'># @api public
2023
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_publish'>publish</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
2024
- <span class='id identifier rubyid_publishing_data'>publishing_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_data'>data</span> <span class='rbrace'>}</span>
2025
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> publishl to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> message: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2026
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='rparen'>)</span>
2027
- <span class='kw'>end</span>
2028
-
2029
- <span class='comment'># callback executes after connection is opened and delegates action to actor
2030
- </span> <span class='comment'>#
2031
- </span> <span class='comment'># @return [void]
2032
- </span> <span class='comment'>#
2033
- </span> <span class='comment'># @api public
2034
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_open'>on_open</span>
2035
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> websocket connection opened</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2036
- <span class='ivar'>@connect_blk</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
2037
- <span class='kw'>end</span>
2038
-
2039
- <span class='comment'># callback executes when actor receives a message from a subscribed channel
2040
- </span> <span class='comment'># and parses the message using JSON.parse and dispatches the parsed
2041
- </span> <span class='comment'># message to the original actor that made the connection
2042
- </span> <span class='comment'>#
2043
- </span> <span class='comment'># @param [JSON] data
2044
- </span> <span class='comment'>#
2045
- </span> <span class='comment'># @return [void]
2046
- </span> <span class='comment'>#
2047
- </span> <span class='comment'># @api public
2048
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
2049
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received plain </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_data'>data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2050
- <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
2051
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2052
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2053
- <span class='kw'>end</span>
2054
-
2055
- <span class='comment'># callback executes when connection closes
2056
- </span> <span class='comment'>#
2057
- </span> <span class='comment'># @param [String] code
2058
- </span> <span class='comment'>#
2059
- </span> <span class='comment'># @param [String] reason
2060
- </span> <span class='comment'>#
2061
- </span> <span class='comment'># @return [void]
2062
- </span> <span class='comment'>#
2063
- </span> <span class='comment'># @api public
2064
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
2065
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_terminate'>terminate</span>
2066
- <span class='id identifier rubyid_terminate'>terminate</span>
2067
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> dispatching on close </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_code'>code</span><span class='embexpr_end'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_reason'>reason</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2068
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
2069
- <span class='kw'>end</span>
2070
-
2071
- <span class='id identifier rubyid_private'>private</span>
2072
-
2073
- <span class='comment'># method used to send messages to the webserver
2074
- </span> <span class='comment'># checks too see if the message is a hash and if it is it will transform it to JSON and send it to the webser
2075
- </span> <span class='comment'># otherwise will construct a JSON object that will have the key action with the value &#39;message&quot; and the key message witth the parameter&#39;s value
2076
- </span> <span class='comment'>#
2077
- </span> <span class='comment'># @param [Hash] message
2078
- </span> <span class='comment'>#
2079
- </span> <span class='comment'># @return [void]
2080
- </span> <span class='comment'>#
2081
- </span> <span class='comment'># @api private
2082
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2083
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='kw'>nil</span>
2084
- <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
2085
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2086
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
2087
- <span class='kw'>else</span>
2088
- <span class='id identifier rubyid_text_messsage'>text_messsage</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='label'>action:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>message</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2089
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_text_messsage'>text_messsage</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2090
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_text_messsage'>text_messsage</span>
2091
- <span class='kw'>end</span>
2092
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_text'>text</span> <span class='id identifier rubyid_final_message'>final_message</span>
2093
- <span class='kw'>end</span>
2094
- <span class='kw'>end</span></pre>
2095
- </td>
2096
- </tr>
2097
- </table>
2098
- </div>
2099
-
2100
-
2101
- <span id="options=-instance_method"></span>
2102
- <div class="method_details ">
2103
- <h3 class="signature " id="options-instance_method">
2104
-
2105
- - (<tt>Hash</tt>) <strong>options</strong>
2106
-
2107
-
2108
-
2109
-
2110
-
2111
- </h3><div class="docstring">
2112
- <div class="discussion">
2113
-
2114
- <p>Returns the options that can be used to connect to webser and send
2115
- additional data</p>
2116
-
2117
-
2118
- </div>
2119
- </div>
2120
- <div class="tags">
2121
-
2122
- <p class="tag_title">Returns:</p>
2123
- <ul class="return">
2124
-
2125
- <li>
2126
-
2127
-
2128
- <span class='type'>(<tt>Hash</tt>)</span>
2129
-
2130
-
2131
-
2132
- &mdash;
2133
- <div class='inline'>
2134
- <p>the options that can be used to connect to webser and send additional data</p>
2135
- </div>
2136
-
2137
- </li>
2138
-
2139
- </ul>
2140
-
2141
- </div><table class="source_code">
2142
- <tr>
2143
- <td>
2144
- <pre class="lines">
2145
-
2146
-
2147
- 28
2148
- 29
2149
- 30
2150
- 31
2151
- 32
2152
- 33
2153
- 34
2154
- 35
2155
- 36
2156
- 37
2157
- 38
2158
- 39
2159
- 40
2160
- 41
2161
- 42
2162
- 43
2163
- 44
2164
- 45
2165
- 46
2166
- 47
2167
- 48
2168
- 49
2169
- 50
2170
- 51
2171
- 52
2172
- 53
2173
- 54
2174
- 55
2175
- 56
2176
- 57
2177
- 58
2178
- 59
2179
- 60
2180
- 61
2181
- 62
2182
- 63
2183
- 64
2184
- 65
2185
- 66
2186
- 67
2187
- 68
2188
- 69
2189
- 70
2190
- 71
2191
- 72
2192
- 73
2193
- 74
2194
- 75
2195
- 76
2196
- 77
2197
- 78
2198
- 79
2199
- 80
2200
- 81
2201
- 82
2202
- 83
2203
- 84
2204
- 85
2205
- 86
2206
- 87
2207
- 88
2208
- 89
2209
- 90
2210
- 91
2211
- 92
2212
- 93
2213
- 94
2214
- 95
2215
- 96
2216
- 97
2217
- 98
2218
- 99
2219
- 100
2220
- 101
2221
- 102
2222
- 103
2223
- 104
2224
- 105
2225
- 106
2226
- 107
2227
- 108
2228
- 109
2229
- 110
2230
- 111
2231
- 112
2232
- 113
2233
- 114
2234
- 115
2235
- 116
2236
- 117
2237
- 118
2238
- 119
2239
- 120
2240
- 121
2241
- 122
2242
- 123
2243
- 124
2244
- 125
2245
- 126
2246
- 127
2247
- 128
2248
- 129
2249
- 130
2250
- 131
2251
- 132
2252
- 133
2253
- 134
2254
- 135
2255
- 136
2256
- 137
2257
- 138
2258
- 139
2259
- 140
2260
- 141
2261
- 142
2262
- 143
2263
- 144
2264
- 145
2265
- 146
2266
- 147
2267
- 148
2268
- 149
2269
- 150
2270
- 151
2271
- 152
2272
- 153
2273
- 154
2274
- 155
2275
- 156
2276
- 157
2277
- 158
2278
- 159
2279
- 160
2280
- 161
2281
- 162
2282
- 163
2283
- 164
2284
- 165
2285
- 166
2286
- 167
2287
- 168
2288
- 169
2289
- 170
2290
- 171
2291
- 172
2292
- 173
2293
- 174
2294
- 175
2295
- 176</pre>
2296
- </td>
2297
- <td>
2298
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 28</span>
2299
-
2300
- <span class='kw'>class</span> <span class='const'>PubSubWorker</span>
2301
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span>
2302
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>Logger</span>
2303
- <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:actor</span><span class='comma'>,</span> <span class='symbol'>:connect_blk</span><span class='comma'>,</span> <span class='symbol'>:client</span><span class='comma'>,</span> <span class='symbol'>:options</span><span class='comma'>,</span> <span class='symbol'>:hostname</span><span class='comma'>,</span> <span class='symbol'>:port</span><span class='comma'>,</span> <span class='symbol'>:path</span>
2304
-
2305
- <span class='comment'># receives a list of options that are used to connect to the webserver and an actor to which the callbacks are delegated to
2306
- </span> <span class='comment'># when receiving messages from a channel
2307
- </span> <span class='comment'>#
2308
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
2309
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
2310
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
2311
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
2312
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
2313
- </span> <span class='comment'>#
2314
- </span> <span class='comment'># @param [Proc] connect_blk Block that will execute after the connection is opened
2315
- </span> <span class='comment'>#
2316
- </span> <span class='comment'># @return [void]
2317
- </span> <span class='comment'>#
2318
- </span> <span class='comment'># @api public
2319
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_connect_blk'>connect_blk</span><span class='rparen'>)</span>
2320
- <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
2321
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>: Please provide an actor in the options list!!!</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
2322
- <span class='ivar'>@connect_blk</span> <span class='op'>=</span> <span class='id identifier rubyid_connect_blk'>connect_blk</span>
2323
- <span class='ivar'>@client</span> <span class='op'>=</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>WebSocket</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ws://</span><span class='embexpr_beg'>#{</span><span class='ivar'>@hostname</span><span class='embexpr_end'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='ivar'>@port</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='rparen'>)</span>
2324
- <span class='kw'>end</span>
2325
-
2326
- <span class='comment'># check the options list for values and sets default values if not found
2327
- </span> <span class='comment'>#
2328
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
2329
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
2330
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
2331
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
2332
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
2333
- </span> <span class='comment'>#
2334
- </span> <span class='comment'># @return [void]
2335
- </span> <span class='comment'>#
2336
- </span> <span class='comment'># @api public
2337
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
2338
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Options is not a hash</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
2339
- <span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys!'>stringify_keys!</span>
2340
- <span class='ivar'>@actor</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>actor</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span>
2341
- <span class='ivar'>@hostname</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>hostname</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>HOST</span><span class='rparen'>)</span>
2342
- <span class='ivar'>@port</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>port</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PORT</span><span class='rparen'>)</span>
2343
- <span class='ivar'>@path</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>path</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PATH</span><span class='rparen'>)</span>
2344
- <span class='kw'>end</span>
2345
-
2346
- <span class='comment'># checks if debug is enabled
2347
- </span> <span class='comment'>#
2348
- </span> <span class='comment'>#
2349
- </span> <span class='comment'># @return [boolean]
2350
- </span> <span class='comment'>#
2351
- </span> <span class='comment'># @api public
2352
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2353
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2354
- <span class='kw'>end</span>
2355
-
2356
- <span class='comment'># subscribes to a channel . need to be used inside the connect block passed to the actor
2357
- </span> <span class='comment'>#
2358
- </span> <span class='comment'># @param [string] channel
2359
- </span> <span class='comment'>#
2360
- </span> <span class='comment'># @return [void]
2361
- </span> <span class='comment'>#
2362
- </span> <span class='comment'># @api public
2363
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_subscribe'>subscribe</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
2364
- <span class='id identifier rubyid_subscription_data'>subscription_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='rbrace'>}</span>
2365
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> tries to subscribe </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2366
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='rparen'>)</span>
2367
- <span class='kw'>end</span>
2368
-
2369
- <span class='comment'># publishes to a channel some data (can be anything)
2370
- </span> <span class='comment'>#
2371
- </span> <span class='comment'># @param [string] channel
2372
- </span> <span class='comment'># @param [#to_s] data
2373
- </span> <span class='comment'>#
2374
- </span> <span class='comment'># @return [void]
2375
- </span> <span class='comment'>#
2376
- </span> <span class='comment'># @api public
2377
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_publish'>publish</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
2378
- <span class='id identifier rubyid_publishing_data'>publishing_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_data'>data</span> <span class='rbrace'>}</span>
2379
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> publishl to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> message: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2380
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='rparen'>)</span>
2381
- <span class='kw'>end</span>
2382
-
2383
- <span class='comment'># callback executes after connection is opened and delegates action to actor
2384
- </span> <span class='comment'>#
2385
- </span> <span class='comment'># @return [void]
2386
- </span> <span class='comment'>#
2387
- </span> <span class='comment'># @api public
2388
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_open'>on_open</span>
2389
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> websocket connection opened</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2390
- <span class='ivar'>@connect_blk</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
2391
- <span class='kw'>end</span>
2392
-
2393
- <span class='comment'># callback executes when actor receives a message from a subscribed channel
2394
- </span> <span class='comment'># and parses the message using JSON.parse and dispatches the parsed
2395
- </span> <span class='comment'># message to the original actor that made the connection
2396
- </span> <span class='comment'>#
2397
- </span> <span class='comment'># @param [JSON] data
2398
- </span> <span class='comment'>#
2399
- </span> <span class='comment'># @return [void]
2400
- </span> <span class='comment'>#
2401
- </span> <span class='comment'># @api public
2402
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
2403
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received plain </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_data'>data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2404
- <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
2405
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2406
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2407
- <span class='kw'>end</span>
2408
-
2409
- <span class='comment'># callback executes when connection closes
2410
- </span> <span class='comment'>#
2411
- </span> <span class='comment'># @param [String] code
2412
- </span> <span class='comment'>#
2413
- </span> <span class='comment'># @param [String] reason
2414
- </span> <span class='comment'>#
2415
- </span> <span class='comment'># @return [void]
2416
- </span> <span class='comment'>#
2417
- </span> <span class='comment'># @api public
2418
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
2419
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_terminate'>terminate</span>
2420
- <span class='id identifier rubyid_terminate'>terminate</span>
2421
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> dispatching on close </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_code'>code</span><span class='embexpr_end'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_reason'>reason</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2422
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
2423
- <span class='kw'>end</span>
2424
-
2425
- <span class='id identifier rubyid_private'>private</span>
2426
-
2427
- <span class='comment'># method used to send messages to the webserver
2428
- </span> <span class='comment'># checks too see if the message is a hash and if it is it will transform it to JSON and send it to the webser
2429
- </span> <span class='comment'># otherwise will construct a JSON object that will have the key action with the value &#39;message&quot; and the key message witth the parameter&#39;s value
2430
- </span> <span class='comment'>#
2431
- </span> <span class='comment'># @param [Hash] message
2432
- </span> <span class='comment'>#
2433
- </span> <span class='comment'># @return [void]
2434
- </span> <span class='comment'>#
2435
- </span> <span class='comment'># @api private
2436
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2437
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='kw'>nil</span>
2438
- <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
2439
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2440
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
2441
- <span class='kw'>else</span>
2442
- <span class='id identifier rubyid_text_messsage'>text_messsage</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='label'>action:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>message</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2443
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_text_messsage'>text_messsage</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2444
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_text_messsage'>text_messsage</span>
2445
- <span class='kw'>end</span>
2446
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_text'>text</span> <span class='id identifier rubyid_final_message'>final_message</span>
2447
- <span class='kw'>end</span>
2448
- <span class='kw'>end</span></pre>
2449
- </td>
2450
- </tr>
2451
- </table>
2452
- </div>
2453
-
2454
-
2455
- <span id="path=-instance_method"></span>
2456
- <div class="method_details ">
2457
- <h3 class="signature " id="path-instance_method">
2458
-
2459
- - (<tt>String</tt>) <strong>path</strong>
2460
-
2461
-
2462
-
2463
-
2464
-
2465
- </h3><div class="docstring">
2466
- <div class="discussion">
2467
-
2468
- <p>Returns The hostname on which the webserver runs on</p>
2469
-
2470
-
2471
- </div>
2472
- </div>
2473
- <div class="tags">
2474
-
2475
- <p class="tag_title">Returns:</p>
2476
- <ul class="return">
2477
-
2478
- <li>
2479
-
2480
-
2481
- <span class='type'>(<tt>String</tt>)</span>
2482
-
2483
-
2484
-
2485
- &mdash;
2486
- <div class='inline'>
2487
- <p>The hostname on which the webserver runs on</p>
2488
- </div>
2489
-
2490
- </li>
2491
-
2492
- </ul>
2493
-
2494
- </div><table class="source_code">
2495
- <tr>
2496
- <td>
2497
- <pre class="lines">
2498
-
2499
-
2500
- 28
2501
- 29
2502
- 30
2503
- 31
2504
- 32
2505
- 33
2506
- 34
2507
- 35
2508
- 36
2509
- 37
2510
- 38
2511
- 39
2512
- 40
2513
- 41
2514
- 42
2515
- 43
2516
- 44
2517
- 45
2518
- 46
2519
- 47
2520
- 48
2521
- 49
2522
- 50
2523
- 51
2524
- 52
2525
- 53
2526
- 54
2527
- 55
2528
- 56
2529
- 57
2530
- 58
2531
- 59
2532
- 60
2533
- 61
2534
- 62
2535
- 63
2536
- 64
2537
- 65
2538
- 66
2539
- 67
2540
- 68
2541
- 69
2542
- 70
2543
- 71
2544
- 72
2545
- 73
2546
- 74
2547
- 75
2548
- 76
2549
- 77
2550
- 78
2551
- 79
2552
- 80
2553
- 81
2554
- 82
2555
- 83
2556
- 84
2557
- 85
2558
- 86
2559
- 87
2560
- 88
2561
- 89
2562
- 90
2563
- 91
2564
- 92
2565
- 93
2566
- 94
2567
- 95
2568
- 96
2569
- 97
2570
- 98
2571
- 99
2572
- 100
2573
- 101
2574
- 102
2575
- 103
2576
- 104
2577
- 105
2578
- 106
2579
- 107
2580
- 108
2581
- 109
2582
- 110
2583
- 111
2584
- 112
2585
- 113
2586
- 114
2587
- 115
2588
- 116
2589
- 117
2590
- 118
2591
- 119
2592
- 120
2593
- 121
2594
- 122
2595
- 123
2596
- 124
2597
- 125
2598
- 126
2599
- 127
2600
- 128
2601
- 129
2602
- 130
2603
- 131
2604
- 132
2605
- 133
2606
- 134
2607
- 135
2608
- 136
2609
- 137
2610
- 138
2611
- 139
2612
- 140
2613
- 141
2614
- 142
2615
- 143
2616
- 144
2617
- 145
2618
- 146
2619
- 147
2620
- 148
2621
- 149
2622
- 150
2623
- 151
2624
- 152
2625
- 153
2626
- 154
2627
- 155
2628
- 156
2629
- 157
2630
- 158
2631
- 159
2632
- 160
2633
- 161
2634
- 162
2635
- 163
2636
- 164
2637
- 165
2638
- 166
2639
- 167
2640
- 168
2641
- 169
2642
- 170
2643
- 171
2644
- 172
2645
- 173
2646
- 174
2647
- 175
2648
- 176</pre>
2649
- </td>
2650
- <td>
2651
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 28</span>
2652
-
2653
- <span class='kw'>class</span> <span class='const'>PubSubWorker</span>
2654
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span>
2655
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>Logger</span>
2656
- <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:actor</span><span class='comma'>,</span> <span class='symbol'>:connect_blk</span><span class='comma'>,</span> <span class='symbol'>:client</span><span class='comma'>,</span> <span class='symbol'>:options</span><span class='comma'>,</span> <span class='symbol'>:hostname</span><span class='comma'>,</span> <span class='symbol'>:port</span><span class='comma'>,</span> <span class='symbol'>:path</span>
2657
-
2658
- <span class='comment'># receives a list of options that are used to connect to the webserver and an actor to which the callbacks are delegated to
2659
- </span> <span class='comment'># when receiving messages from a channel
2660
- </span> <span class='comment'>#
2661
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
2662
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
2663
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
2664
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
2665
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
2666
- </span> <span class='comment'>#
2667
- </span> <span class='comment'># @param [Proc] connect_blk Block that will execute after the connection is opened
2668
- </span> <span class='comment'>#
2669
- </span> <span class='comment'># @return [void]
2670
- </span> <span class='comment'>#
2671
- </span> <span class='comment'># @api public
2672
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_connect_blk'>connect_blk</span><span class='rparen'>)</span>
2673
- <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
2674
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>: Please provide an actor in the options list!!!</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
2675
- <span class='ivar'>@connect_blk</span> <span class='op'>=</span> <span class='id identifier rubyid_connect_blk'>connect_blk</span>
2676
- <span class='ivar'>@client</span> <span class='op'>=</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>WebSocket</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ws://</span><span class='embexpr_beg'>#{</span><span class='ivar'>@hostname</span><span class='embexpr_end'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='ivar'>@port</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='rparen'>)</span>
2677
- <span class='kw'>end</span>
2678
-
2679
- <span class='comment'># check the options list for values and sets default values if not found
2680
- </span> <span class='comment'>#
2681
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
2682
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
2683
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
2684
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
2685
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
2686
- </span> <span class='comment'>#
2687
- </span> <span class='comment'># @return [void]
2688
- </span> <span class='comment'>#
2689
- </span> <span class='comment'># @api public
2690
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
2691
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Options is not a hash</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
2692
- <span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys!'>stringify_keys!</span>
2693
- <span class='ivar'>@actor</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>actor</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span>
2694
- <span class='ivar'>@hostname</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>hostname</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>HOST</span><span class='rparen'>)</span>
2695
- <span class='ivar'>@port</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>port</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PORT</span><span class='rparen'>)</span>
2696
- <span class='ivar'>@path</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>path</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PATH</span><span class='rparen'>)</span>
2697
- <span class='kw'>end</span>
2698
-
2699
- <span class='comment'># checks if debug is enabled
2700
- </span> <span class='comment'>#
2701
- </span> <span class='comment'>#
2702
- </span> <span class='comment'># @return [boolean]
2703
- </span> <span class='comment'>#
2704
- </span> <span class='comment'># @api public
2705
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2706
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2707
- <span class='kw'>end</span>
2708
-
2709
- <span class='comment'># subscribes to a channel . need to be used inside the connect block passed to the actor
2710
- </span> <span class='comment'>#
2711
- </span> <span class='comment'># @param [string] channel
2712
- </span> <span class='comment'>#
2713
- </span> <span class='comment'># @return [void]
2714
- </span> <span class='comment'>#
2715
- </span> <span class='comment'># @api public
2716
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_subscribe'>subscribe</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
2717
- <span class='id identifier rubyid_subscription_data'>subscription_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='rbrace'>}</span>
2718
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> tries to subscribe </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2719
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='rparen'>)</span>
2720
- <span class='kw'>end</span>
2721
-
2722
- <span class='comment'># publishes to a channel some data (can be anything)
2723
- </span> <span class='comment'>#
2724
- </span> <span class='comment'># @param [string] channel
2725
- </span> <span class='comment'># @param [#to_s] data
2726
- </span> <span class='comment'>#
2727
- </span> <span class='comment'># @return [void]
2728
- </span> <span class='comment'>#
2729
- </span> <span class='comment'># @api public
2730
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_publish'>publish</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
2731
- <span class='id identifier rubyid_publishing_data'>publishing_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_data'>data</span> <span class='rbrace'>}</span>
2732
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> publishl to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> message: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2733
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='rparen'>)</span>
2734
- <span class='kw'>end</span>
2735
-
2736
- <span class='comment'># callback executes after connection is opened and delegates action to actor
2737
- </span> <span class='comment'>#
2738
- </span> <span class='comment'># @return [void]
2739
- </span> <span class='comment'>#
2740
- </span> <span class='comment'># @api public
2741
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_open'>on_open</span>
2742
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> websocket connection opened</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2743
- <span class='ivar'>@connect_blk</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
2744
- <span class='kw'>end</span>
2745
-
2746
- <span class='comment'># callback executes when actor receives a message from a subscribed channel
2747
- </span> <span class='comment'># and parses the message using JSON.parse and dispatches the parsed
2748
- </span> <span class='comment'># message to the original actor that made the connection
2749
- </span> <span class='comment'>#
2750
- </span> <span class='comment'># @param [JSON] data
2751
- </span> <span class='comment'>#
2752
- </span> <span class='comment'># @return [void]
2753
- </span> <span class='comment'>#
2754
- </span> <span class='comment'># @api public
2755
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
2756
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received plain </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_data'>data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2757
- <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
2758
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2759
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2760
- <span class='kw'>end</span>
2761
-
2762
- <span class='comment'># callback executes when connection closes
2763
- </span> <span class='comment'>#
2764
- </span> <span class='comment'># @param [String] code
2765
- </span> <span class='comment'>#
2766
- </span> <span class='comment'># @param [String] reason
2767
- </span> <span class='comment'>#
2768
- </span> <span class='comment'># @return [void]
2769
- </span> <span class='comment'>#
2770
- </span> <span class='comment'># @api public
2771
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
2772
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_terminate'>terminate</span>
2773
- <span class='id identifier rubyid_terminate'>terminate</span>
2774
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> dispatching on close </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_code'>code</span><span class='embexpr_end'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_reason'>reason</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2775
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
2776
- <span class='kw'>end</span>
2777
-
2778
- <span class='id identifier rubyid_private'>private</span>
2779
-
2780
- <span class='comment'># method used to send messages to the webserver
2781
- </span> <span class='comment'># checks too see if the message is a hash and if it is it will transform it to JSON and send it to the webser
2782
- </span> <span class='comment'># otherwise will construct a JSON object that will have the key action with the value &#39;message&quot; and the key message witth the parameter&#39;s value
2783
- </span> <span class='comment'>#
2784
- </span> <span class='comment'># @param [Hash] message
2785
- </span> <span class='comment'>#
2786
- </span> <span class='comment'># @return [void]
2787
- </span> <span class='comment'>#
2788
- </span> <span class='comment'># @api private
2789
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2790
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='kw'>nil</span>
2791
- <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
2792
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2793
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
2794
- <span class='kw'>else</span>
2795
- <span class='id identifier rubyid_text_messsage'>text_messsage</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='label'>action:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>message</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
2796
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_text_messsage'>text_messsage</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
2797
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_text_messsage'>text_messsage</span>
2798
- <span class='kw'>end</span>
2799
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_text'>text</span> <span class='id identifier rubyid_final_message'>final_message</span>
2800
- <span class='kw'>end</span>
2801
- <span class='kw'>end</span></pre>
2802
- </td>
2803
- </tr>
2804
- </table>
2805
- </div>
2806
-
2807
-
2808
- <span id="port=-instance_method"></span>
2809
- <div class="method_details ">
2810
- <h3 class="signature " id="port-instance_method">
2811
-
2812
- - (<tt>String</tt>) <strong>port</strong>
2813
-
2814
-
2815
-
2816
-
2817
-
2818
- </h3><div class="docstring">
2819
- <div class="discussion">
2820
-
2821
- <p>Returns The port on which the webserver runs on</p>
2822
-
2823
-
2824
- </div>
2825
- </div>
2826
- <div class="tags">
2827
-
2828
- <p class="tag_title">Returns:</p>
2829
- <ul class="return">
2830
-
2831
- <li>
2832
-
2833
-
2834
- <span class='type'>(<tt>String</tt>)</span>
2835
-
2836
-
2837
-
2838
- &mdash;
2839
- <div class='inline'>
2840
- <p>The port on which the webserver runs on</p>
2841
- </div>
2842
-
2843
- </li>
2844
-
2845
- </ul>
2846
-
2847
- </div><table class="source_code">
2848
- <tr>
2849
- <td>
2850
- <pre class="lines">
2851
-
2852
-
2853
- 28
2854
- 29
2855
- 30
2856
- 31
2857
- 32
2858
- 33
2859
- 34
2860
- 35
2861
- 36
2862
- 37
2863
- 38
2864
- 39
2865
- 40
2866
- 41
2867
- 42
2868
- 43
2869
- 44
2870
- 45
2871
- 46
2872
- 47
2873
- 48
2874
- 49
2875
- 50
2876
- 51
2877
- 52
2878
- 53
2879
- 54
2880
- 55
2881
- 56
2882
- 57
2883
- 58
2884
- 59
2885
- 60
2886
- 61
2887
- 62
2888
- 63
2889
- 64
2890
- 65
2891
- 66
2892
- 67
2893
- 68
2894
- 69
2895
- 70
2896
- 71
2897
- 72
2898
- 73
2899
- 74
2900
- 75
2901
- 76
2902
- 77
2903
- 78
2904
- 79
2905
- 80
2906
- 81
2907
- 82
2908
- 83
2909
- 84
2910
- 85
2911
- 86
2912
- 87
2913
- 88
2914
- 89
2915
- 90
2916
- 91
2917
- 92
2918
- 93
2919
- 94
2920
- 95
2921
- 96
2922
- 97
2923
- 98
2924
- 99
2925
- 100
2926
- 101
2927
- 102
2928
- 103
2929
- 104
2930
- 105
2931
- 106
2932
- 107
2933
- 108
2934
- 109
2935
- 110
2936
- 111
2937
- 112
2938
- 113
2939
- 114
2940
- 115
2941
- 116
2942
- 117
2943
- 118
2944
- 119
2945
- 120
2946
- 121
2947
- 122
2948
- 123
2949
- 124
2950
- 125
2951
- 126
2952
- 127
2953
- 128
2954
- 129
2955
- 130
2956
- 131
2957
- 132
2958
- 133
2959
- 134
2960
- 135
2961
- 136
2962
- 137
2963
- 138
2964
- 139
2965
- 140
2966
- 141
2967
- 142
2968
- 143
2969
- 144
2970
- 145
2971
- 146
2972
- 147
2973
- 148
2974
- 149
2975
- 150
2976
- 151
2977
- 152
2978
- 153
2979
- 154
2980
- 155
2981
- 156
2982
- 157
2983
- 158
2984
- 159
2985
- 160
2986
- 161
2987
- 162
2988
- 163
2989
- 164
2990
- 165
2991
- 166
2992
- 167
2993
- 168
2994
- 169
2995
- 170
2996
- 171
2997
- 172
2998
- 173
2999
- 174
3000
- 175
3001
- 176</pre>
3002
- </td>
3003
- <td>
3004
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 28</span>
3005
-
3006
- <span class='kw'>class</span> <span class='const'>PubSubWorker</span>
3007
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span>
3008
- <span class='id identifier rubyid_include'>include</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>Logger</span>
3009
- <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:actor</span><span class='comma'>,</span> <span class='symbol'>:connect_blk</span><span class='comma'>,</span> <span class='symbol'>:client</span><span class='comma'>,</span> <span class='symbol'>:options</span><span class='comma'>,</span> <span class='symbol'>:hostname</span><span class='comma'>,</span> <span class='symbol'>:port</span><span class='comma'>,</span> <span class='symbol'>:path</span>
3010
-
3011
- <span class='comment'># receives a list of options that are used to connect to the webserver and an actor to which the callbacks are delegated to
3012
- </span> <span class='comment'># when receiving messages from a channel
3013
- </span> <span class='comment'>#
3014
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
3015
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
3016
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
3017
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
3018
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
3019
- </span> <span class='comment'>#
3020
- </span> <span class='comment'># @param [Proc] connect_blk Block that will execute after the connection is opened
3021
- </span> <span class='comment'>#
3022
- </span> <span class='comment'># @return [void]
3023
- </span> <span class='comment'>#
3024
- </span> <span class='comment'># @api public
3025
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_connect_blk'>connect_blk</span><span class='rparen'>)</span>
3026
- <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
3027
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>: Please provide an actor in the options list!!!</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
3028
- <span class='ivar'>@connect_blk</span> <span class='op'>=</span> <span class='id identifier rubyid_connect_blk'>connect_blk</span>
3029
- <span class='ivar'>@client</span> <span class='op'>=</span> <span class='const'>Celluloid</span><span class='op'>::</span><span class='const'>WebSocket</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ws://</span><span class='embexpr_beg'>#{</span><span class='ivar'>@hostname</span><span class='embexpr_end'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='ivar'>@port</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='rparen'>)</span>
3030
- <span class='kw'>end</span>
3031
-
3032
- <span class='comment'># check the options list for values and sets default values if not found
3033
- </span> <span class='comment'>#
3034
- </span> <span class='comment'># @param [Hash] options the options that can be used to connect to webser and send additional data
3035
- </span> <span class='comment'># @option options [String] :actor The actor that made the connection
3036
- </span> <span class='comment'># @option options [String]:hostname The hostname on which the webserver runs on
3037
- </span> <span class='comment'># @option options [String] :port The port on which the webserver runs on
3038
- </span> <span class='comment'># @option options [String] :path The request path that the webserver accepts
3039
- </span> <span class='comment'>#
3040
- </span> <span class='comment'># @return [void]
3041
- </span> <span class='comment'>#
3042
- </span> <span class='comment'># @api public
3043
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
3044
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Options is not a hash</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
3045
- <span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys!'>stringify_keys!</span>
3046
- <span class='ivar'>@actor</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>actor</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span>
3047
- <span class='ivar'>@hostname</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>hostname</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>HOST</span><span class='rparen'>)</span>
3048
- <span class='ivar'>@port</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>port</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PORT</span><span class='rparen'>)</span>
3049
- <span class='ivar'>@path</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>path</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PATH</span><span class='rparen'>)</span>
3050
- <span class='kw'>end</span>
3051
-
3052
- <span class='comment'># checks if debug is enabled
3053
- </span> <span class='comment'>#
3054
- </span> <span class='comment'>#
3055
- </span> <span class='comment'># @return [boolean]
3056
- </span> <span class='comment'>#
3057
- </span> <span class='comment'># @api public
3058
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3059
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3060
- <span class='kw'>end</span>
3061
-
3062
- <span class='comment'># subscribes to a channel . need to be used inside the connect block passed to the actor
3063
- </span> <span class='comment'>#
3064
- </span> <span class='comment'># @param [string] channel
3065
- </span> <span class='comment'>#
3066
- </span> <span class='comment'># @return [void]
3067
- </span> <span class='comment'>#
3068
- </span> <span class='comment'># @api public
3069
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_subscribe'>subscribe</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
3070
- <span class='id identifier rubyid_subscription_data'>subscription_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='rbrace'>}</span>
3071
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> tries to subscribe </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3072
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='rparen'>)</span>
3073
- <span class='kw'>end</span>
3074
-
3075
- <span class='comment'># publishes to a channel some data (can be anything)
3076
- </span> <span class='comment'>#
3077
- </span> <span class='comment'># @param [string] channel
3078
- </span> <span class='comment'># @param [#to_s] data
3079
- </span> <span class='comment'>#
3080
- </span> <span class='comment'># @return [void]
3081
- </span> <span class='comment'>#
3082
- </span> <span class='comment'># @api public
3083
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_publish'>publish</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
3084
- <span class='id identifier rubyid_publishing_data'>publishing_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_data'>data</span> <span class='rbrace'>}</span>
3085
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> publishl to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> message: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3086
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='rparen'>)</span>
3087
- <span class='kw'>end</span>
3088
-
3089
- <span class='comment'># callback executes after connection is opened and delegates action to actor
3090
- </span> <span class='comment'>#
3091
- </span> <span class='comment'># @return [void]
3092
- </span> <span class='comment'>#
3093
- </span> <span class='comment'># @api public
3094
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_open'>on_open</span>
3095
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> websocket connection opened</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3096
- <span class='ivar'>@connect_blk</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
3097
- <span class='kw'>end</span>
3098
-
3099
- <span class='comment'># callback executes when actor receives a message from a subscribed channel
3100
- </span> <span class='comment'># and parses the message using JSON.parse and dispatches the parsed
3101
- </span> <span class='comment'># message to the original actor that made the connection
3102
- </span> <span class='comment'>#
3103
- </span> <span class='comment'># @param [JSON] data
3104
- </span> <span class='comment'>#
3105
- </span> <span class='comment'># @return [void]
3106
- </span> <span class='comment'>#
3107
- </span> <span class='comment'># @api public
3108
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
3109
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received plain </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_data'>data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3110
- <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
3111
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3112
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
3113
- <span class='kw'>end</span>
3114
-
3115
- <span class='comment'># callback executes when connection closes
3116
- </span> <span class='comment'>#
3117
- </span> <span class='comment'># @param [String] code
3118
- </span> <span class='comment'>#
3119
- </span> <span class='comment'># @param [String] reason
3120
- </span> <span class='comment'>#
3121
- </span> <span class='comment'># @return [void]
3122
- </span> <span class='comment'>#
3123
- </span> <span class='comment'># @api public
3124
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
3125
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_terminate'>terminate</span>
3126
- <span class='id identifier rubyid_terminate'>terminate</span>
3127
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> dispatching on close </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_code'>code</span><span class='embexpr_end'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_reason'>reason</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3128
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
3129
- <span class='kw'>end</span>
3130
-
3131
- <span class='id identifier rubyid_private'>private</span>
3132
-
3133
- <span class='comment'># method used to send messages to the webserver
3134
- </span> <span class='comment'># checks too see if the message is a hash and if it is it will transform it to JSON and send it to the webser
3135
- </span> <span class='comment'># otherwise will construct a JSON object that will have the key action with the value &#39;message&quot; and the key message witth the parameter&#39;s value
3136
- </span> <span class='comment'>#
3137
- </span> <span class='comment'># @param [Hash] message
3138
- </span> <span class='comment'>#
3139
- </span> <span class='comment'># @return [void]
3140
- </span> <span class='comment'>#
3141
- </span> <span class='comment'># @api private
3142
- </span> <span class='kw'>def</span> <span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
3143
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='kw'>nil</span>
3144
- <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
3145
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3146
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
3147
- <span class='kw'>else</span>
3148
- <span class='id identifier rubyid_text_messsage'>text_messsage</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='label'>action:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>message</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>message:</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
3149
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> sends JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_text_messsage'>text_messsage</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3150
- <span class='id identifier rubyid_final_message'>final_message</span> <span class='op'>=</span> <span class='id identifier rubyid_text_messsage'>text_messsage</span>
3151
- <span class='kw'>end</span>
3152
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_text'>text</span> <span class='id identifier rubyid_final_message'>final_message</span>
3153
- <span class='kw'>end</span>
3154
- <span class='kw'>end</span></pre>
3155
- </td>
3156
- </tr>
3157
- </table>
3158
- </div>
3159
-
3160
- </div>
3161
-
3162
-
3163
- <div id="instance_method_details" class="method_details_list">
3164
- <h2>Instance Method Details</h2>
3165
-
3166
-
3167
- <div class="method_details first">
3168
- <h3 class="signature first" id="debug_enabled?-instance_method">
3169
-
3170
- - (<tt>boolean</tt>) <strong>debug_enabled?</strong>
3171
-
3172
-
3173
-
3174
-
3175
-
3176
- </h3><div class="docstring">
3177
- <div class="discussion">
3178
-
3179
- <p>checks if debug is enabled</p>
3180
-
3181
-
3182
- </div>
3183
- </div>
3184
- <div class="tags">
3185
-
3186
- <p class="tag_title">Returns:</p>
3187
- <ul class="return">
3188
-
3189
- <li>
3190
-
3191
-
3192
- <span class='type'>(<tt>boolean</tt>)</span>
3193
-
3194
-
3195
-
3196
- </li>
3197
-
3198
- </ul>
3199
-
3200
- </div><table class="source_code">
3201
- <tr>
3202
- <td>
3203
- <pre class="lines">
3204
-
3205
-
3206
- 80
3207
- 81
3208
- 82</pre>
3209
- </td>
3210
- <td>
3211
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 80</span>
3212
-
3213
- <span class='kw'>def</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3214
- <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='period'>.</span><span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3215
- <span class='kw'>end</span></pre>
3216
- </td>
3217
- </tr>
3218
- </table>
3219
- </div>
3220
-
3221
- <div class="method_details ">
3222
- <h3 class="signature " id="on_close-instance_method">
3223
-
3224
- - (<tt>void</tt>) <strong>on_close</strong>(code, reason)
3225
-
3226
-
3227
-
3228
-
3229
-
3230
- </h3><div class="docstring">
3231
- <div class="discussion">
3232
- <p class="note returns_void">This method returns an undefined value.</p>
3233
- <p>callback executes when connection closes</p>
3234
-
3235
-
3236
- </div>
3237
- </div>
3238
- <div class="tags">
3239
- <p class="tag_title">Parameters:</p>
3240
- <ul class="param">
3241
-
3242
- <li>
3243
-
3244
- <span class='name'>code</span>
3245
-
3246
-
3247
- <span class='type'>(<tt>String</tt>)</span>
3248
-
3249
-
3250
-
3251
- </li>
3252
-
3253
- <li>
3254
-
3255
- <span class='name'>reason</span>
3256
-
3257
-
3258
- <span class='type'>(<tt>String</tt>)</span>
3259
-
3260
-
3261
-
3262
- </li>
3263
-
3264
- </ul>
3265
-
3266
-
3267
- </div><table class="source_code">
3268
- <tr>
3269
- <td>
3270
- <pre class="lines">
3271
-
3272
-
3273
- 146
3274
- 147
3275
- 148
3276
- 149
3277
- 150
3278
- 151</pre>
3279
- </td>
3280
- <td>
3281
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 146</span>
3282
-
3283
- <span class='kw'>def</span> <span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
3284
- <span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_terminate'>terminate</span>
3285
- <span class='id identifier rubyid_terminate'>terminate</span>
3286
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> dispatching on close </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_code'>code</span><span class='embexpr_end'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_reason'>reason</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3287
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_close'>on_close</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_reason'>reason</span><span class='rparen'>)</span>
3288
- <span class='kw'>end</span></pre>
3289
- </td>
3290
- </tr>
3291
- </table>
3292
- </div>
3293
-
3294
- <div class="method_details ">
3295
- <h3 class="signature " id="on_message-instance_method">
3296
-
3297
- - (<tt>void</tt>) <strong>on_message</strong>(data)
3298
-
3299
-
3300
-
3301
-
3302
-
3303
- </h3><div class="docstring">
3304
- <div class="discussion">
3305
- <p class="note returns_void">This method returns an undefined value.</p>
3306
- <p>callback executes when actor receives a message from a subscribed channel
3307
- and parses the message using JSON.parse and dispatches the parsed message
3308
- to the original actor that made the connection</p>
3309
-
3310
-
3311
- </div>
3312
- </div>
3313
- <div class="tags">
3314
- <p class="tag_title">Parameters:</p>
3315
- <ul class="param">
3316
-
3317
- <li>
3318
-
3319
- <span class='name'>data</span>
3320
-
3321
-
3322
- <span class='type'>(<tt>JSON</tt>)</span>
3323
-
3324
-
3325
-
3326
- </li>
3327
-
3328
- </ul>
3329
-
3330
-
3331
- </div><table class="source_code">
3332
- <tr>
3333
- <td>
3334
- <pre class="lines">
3335
-
3336
-
3337
- 130
3338
- 131
3339
- 132
3340
- 133
3341
- 134
3342
- 135</pre>
3343
- </td>
3344
- <td>
3345
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 130</span>
3346
-
3347
- <span class='kw'>def</span> <span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
3348
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received plain </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_data'>data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3349
- <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
3350
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> received JSON </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3351
- <span class='ivar'>@actor</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_on_message'>on_message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span>
3352
- <span class='kw'>end</span></pre>
3353
- </td>
3354
- </tr>
3355
- </table>
3356
- </div>
3357
-
3358
- <div class="method_details ">
3359
- <h3 class="signature " id="on_open-instance_method">
3360
-
3361
- - (<tt>void</tt>) <strong>on_open</strong>
3362
-
3363
-
3364
-
3365
-
3366
-
3367
- </h3><div class="docstring">
3368
- <div class="discussion">
3369
- <p class="note returns_void">This method returns an undefined value.</p>
3370
- <p>callback executes after connection is opened and delegates action to actor</p>
3371
-
3372
-
3373
- </div>
3374
- </div>
3375
- <div class="tags">
3376
-
3377
-
3378
- </div><table class="source_code">
3379
- <tr>
3380
- <td>
3381
- <pre class="lines">
3382
-
3383
-
3384
- 116
3385
- 117
3386
- 118
3387
- 119</pre>
3388
- </td>
3389
- <td>
3390
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 116</span>
3391
-
3392
- <span class='kw'>def</span> <span class='id identifier rubyid_on_open'>on_open</span>
3393
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> websocket connection opened</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3394
- <span class='ivar'>@connect_blk</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span> <span class='const'>Actor</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
3395
- <span class='kw'>end</span></pre>
3396
- </td>
3397
- </tr>
3398
- </table>
3399
- </div>
3400
-
3401
- <div class="method_details ">
3402
- <h3 class="signature " id="parse_options-instance_method">
3403
-
3404
- - (<tt>void</tt>) <strong>parse_options</strong>(options)
3405
-
3406
-
3407
-
3408
-
3409
-
3410
- </h3><div class="docstring">
3411
- <div class="discussion">
3412
- <p class="note returns_void">This method returns an undefined value.</p>
3413
- <p>check the options list for values and sets default values if not found</p>
3414
-
3415
-
3416
- </div>
3417
- </div>
3418
- <div class="tags">
3419
- <p class="tag_title">Parameters:</p>
3420
- <ul class="param">
3421
-
3422
- <li>
3423
-
3424
- <span class='name'>options</span>
3425
-
3426
-
3427
- <span class='type'>(<tt>Hash</tt>)</span>
3428
-
3429
-
3430
-
3431
- &mdash;
3432
- <div class='inline'>
3433
- <p>the options that can be used to connect to webser and send additional data</p>
3434
- </div>
3435
-
3436
- </li>
3437
-
3438
- </ul>
3439
-
3440
-
3441
-
3442
-
3443
- <p class="tag_title">Options Hash (<tt>options</tt>):</p>
3444
- <ul class="option">
3445
-
3446
- <li>
3447
- <span class="name">:actor</span>
3448
- <span class="type">(<tt>String</tt>)</span>
3449
- <span class="default">
3450
-
3451
- </span>
3452
-
3453
- &mdash; <div class='inline'>
3454
- <p>The actor that made the connection</p>
3455
- </div>
3456
-
3457
- </li>
3458
-
3459
- <li>
3460
- <span class="name">:hostname</span>
3461
- <span class="type">(<tt>String</tt>)</span>
3462
- <span class="default">
3463
-
3464
- </span>
3465
-
3466
- &mdash; <div class='inline'>
3467
- <p>The hostname on which the webserver runs on</p>
3468
- </div>
3469
-
3470
- </li>
3471
-
3472
- <li>
3473
- <span class="name">:port</span>
3474
- <span class="type">(<tt>String</tt>)</span>
3475
- <span class="default">
3476
-
3477
- </span>
3478
-
3479
- &mdash; <div class='inline'>
3480
- <p>The port on which the webserver runs on</p>
3481
- </div>
3482
-
3483
- </li>
3484
-
3485
- <li>
3486
- <span class="name">:path</span>
3487
- <span class="type">(<tt>String</tt>)</span>
3488
- <span class="default">
3489
-
3490
- </span>
3491
-
3492
- &mdash; <div class='inline'>
3493
- <p>The request path that the webserver accepts</p>
3494
- </div>
3495
-
3496
- </li>
3497
-
3498
- </ul>
3499
-
3500
-
3501
-
3502
- </div><table class="source_code">
3503
- <tr>
3504
- <td>
3505
- <pre class="lines">
3506
-
3507
-
3508
- 65
3509
- 66
3510
- 67
3511
- 68
3512
- 69
3513
- 70
3514
- 71
3515
- 72</pre>
3516
- </td>
3517
- <td>
3518
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 65</span>
3519
-
3520
- <span class='kw'>def</span> <span class='id identifier rubyid_parse_options'>parse_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
3521
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Options is not a hash</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
3522
- <span class='ivar'>@options</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys!'>stringify_keys!</span>
3523
- <span class='ivar'>@actor</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>actor</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span>
3524
- <span class='ivar'>@hostname</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>hostname</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>HOST</span><span class='rparen'>)</span>
3525
- <span class='ivar'>@port</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>port</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PORT</span><span class='rparen'>)</span>
3526
- <span class='ivar'>@path</span> <span class='op'>=</span> <span class='ivar'>@options</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>path</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='const'>CelluloidPubsub</span><span class='op'>::</span><span class='const'>WebServer</span><span class='op'>::</span><span class='const'>PATH</span><span class='rparen'>)</span>
3527
- <span class='kw'>end</span></pre>
3528
- </td>
3529
- </tr>
3530
- </table>
3531
- </div>
3532
-
3533
- <div class="method_details ">
3534
- <h3 class="signature " id="publish-instance_method">
3535
-
3536
- - (<tt>void</tt>) <strong>publish</strong>(channel, data)
3537
-
3538
-
3539
-
3540
-
3541
-
3542
- </h3><div class="docstring">
3543
- <div class="discussion">
3544
- <p class="note returns_void">This method returns an undefined value.</p>
3545
- <p>publishes to a channel some data (can be anything)</p>
3546
-
3547
-
3548
- </div>
3549
- </div>
3550
- <div class="tags">
3551
- <p class="tag_title">Parameters:</p>
3552
- <ul class="param">
3553
-
3554
- <li>
3555
-
3556
- <span class='name'>channel</span>
3557
-
3558
-
3559
- <span class='type'>(<tt>string</tt>)</span>
3560
-
3561
-
3562
-
3563
- </li>
3564
-
3565
- <li>
3566
-
3567
- <span class='name'>data</span>
3568
-
3569
-
3570
- <span class='type'>(<tt>#to_s</tt>)</span>
3571
-
3572
-
3573
-
3574
- </li>
3575
-
3576
- </ul>
3577
-
3578
-
3579
- </div><table class="source_code">
3580
- <tr>
3581
- <td>
3582
- <pre class="lines">
3583
-
3584
-
3585
- 105
3586
- 106
3587
- 107
3588
- 108
3589
- 109</pre>
3590
- </td>
3591
- <td>
3592
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 105</span>
3593
-
3594
- <span class='kw'>def</span> <span class='id identifier rubyid_publish'>publish</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
3595
- <span class='id identifier rubyid_publishing_data'>publishing_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>publish</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>data</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_data'>data</span> <span class='rbrace'>}</span>
3596
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> publishl to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_channel'>channel</span><span class='embexpr_end'>}</span><span class='tstring_content'> message: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3597
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_publishing_data'>publishing_data</span><span class='rparen'>)</span>
3598
- <span class='kw'>end</span></pre>
3599
- </td>
3600
- </tr>
3601
- </table>
3602
- </div>
3603
-
3604
- <div class="method_details ">
3605
- <h3 class="signature " id="subscribe-instance_method">
3606
-
3607
- - (<tt>void</tt>) <strong>subscribe</strong>(channel)
3608
-
3609
-
3610
-
3611
-
3612
-
3613
- </h3><div class="docstring">
3614
- <div class="discussion">
3615
- <p class="note returns_void">This method returns an undefined value.</p>
3616
- <p>subscribes to a channel . need to be used inside the connect block passed
3617
- to the actor</p>
3618
-
3619
-
3620
- </div>
3621
- </div>
3622
- <div class="tags">
3623
- <p class="tag_title">Parameters:</p>
3624
- <ul class="param">
3625
-
3626
- <li>
3627
-
3628
- <span class='name'>channel</span>
3629
-
3630
-
3631
- <span class='type'>(<tt>string</tt>)</span>
3632
-
3633
-
3634
-
3635
- </li>
3636
-
3637
- </ul>
3638
-
3639
-
3640
- </div><table class="source_code">
3641
- <tr>
3642
- <td>
3643
- <pre class="lines">
3644
-
3645
-
3646
- 91
3647
- 92
3648
- 93
3649
- 94
3650
- 95</pre>
3651
- </td>
3652
- <td>
3653
- <pre class="code"><span class="info file"># File 'lib/celluloid_pubsub/client_pubsub.rb', line 91</span>
3654
-
3655
- <span class='kw'>def</span> <span class='id identifier rubyid_subscribe'>subscribe</span><span class='lparen'>(</span><span class='id identifier rubyid_channel'>channel</span><span class='rparen'>)</span>
3656
- <span class='id identifier rubyid_subscription_data'>subscription_data</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>client_action</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>subscribe</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>channel</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_channel'>channel</span> <span class='rbrace'>}</span>
3657
- <span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> tries to subscribe </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_debug_enabled?'>debug_enabled?</span>
3658
- <span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_chat'>chat</span><span class='lparen'>(</span><span class='id identifier rubyid_subscription_data'>subscription_data</span><span class='rparen'>)</span>
3659
- <span class='kw'>end</span></pre>
3660
- </td>
3661
- </tr>
3662
- </table>
3663
- </div>
3664
-
3665
- </div>
3666
-
3667
- </div>
3668
-
3669
- <div id="footer">
3670
- Generated on Fri Mar 13 18:05:42 2015 by
3671
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
3672
- 0.8.7.6 (ruby-2.0.0).
3673
- </div>
3674
-
3675
- </body>
3676
- </html>