ionian 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/Ionian/Extension/IO.html +636 -0
- data/doc/Ionian/Extension/Socket.html +286 -0
- data/doc/Ionian/Extension.html +99 -0
- data/doc/Ionian/IO.html +2 -2
- data/doc/Ionian/Socket.html +286 -0
- data/doc/created.rid +4 -3
- data/doc/index.html +2 -0
- data/doc/js/search_index.js +1 -1
- data/doc/table_of_contents.html +23 -0
- data/lib/ionian/io.rb +2 -2
- data/lib/ionian/socket.rb +38 -0
- data/lib/ionian.rb +1 -0
- metadata +41 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bcea8e76124f692dbb73310c5eb10545318c838
|
4
|
+
data.tar.gz: 85c23350aa38dcce18ccbb9df3ac7fd32e1d6f05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1c181e45023688d2b978c396a488e1614dbecc7d5b4b7e790cfed11db794d2df1de267510a20c3fbc83922853f166c20823bdf7a6260bb5a58060d23929f1c7
|
7
|
+
data.tar.gz: 90d906bd4f2ca67bde0f4bb1dea8bdcc305ef9a6d85af1eea56bc3a5c58ff96bf87ed56e336214601facdd4b9195d057fb35b09c95a51ef59b36920e4298f3c7
|
@@ -0,0 +1,636 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>module Ionian::Extension::IO - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<link href="../../fonts.css" rel="stylesheet">
|
10
|
+
<link href="../../rdoc.css" rel="stylesheet">
|
11
|
+
|
12
|
+
<script type="text/javascript">
|
13
|
+
var rdoc_rel_prefix = "../../";
|
14
|
+
</script>
|
15
|
+
|
16
|
+
<script src="../../js/jquery.js"></script>
|
17
|
+
<script src="../../js/navigation.js"></script>
|
18
|
+
<script src="../../js/search_index.js"></script>
|
19
|
+
<script src="../../js/search.js"></script>
|
20
|
+
<script src="../../js/searcher.js"></script>
|
21
|
+
<script src="../../js/darkfish.js"></script>
|
22
|
+
|
23
|
+
|
24
|
+
<body id="top" role="document" class="module">
|
25
|
+
<nav role="navigation">
|
26
|
+
<div id="project-navigation">
|
27
|
+
<div id="home-section" role="banner" class="nav-section">
|
28
|
+
<h2>
|
29
|
+
<a href="../../index.html" rel="home">Home</a>
|
30
|
+
</h2>
|
31
|
+
|
32
|
+
<h3>
|
33
|
+
<a href="../../table_of_contents.html#pages">Pages</a>
|
34
|
+
<a href="../../table_of_contents.html#classes">Classes</a>
|
35
|
+
<a href="../../table_of_contents.html#methods">Methods</a>
|
36
|
+
</h3>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
40
|
+
<form action="#" method="get" accept-charset="utf-8">
|
41
|
+
<div id="search-field-wrapper">
|
42
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
43
|
+
aria-autocomplete="list" aria-controls="search-results"
|
44
|
+
type="text" name="search" placeholder="Search"
|
45
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<ul id="search-results" aria-label="Search Results"
|
49
|
+
aria-busy="false" aria-expanded="false"
|
50
|
+
aria-atomic="false" aria-live="polite"
|
51
|
+
aria-relevant="all" class="initially-hidden"></ul>
|
52
|
+
</form>
|
53
|
+
</div>
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
<div id="class-metadata">
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
<!-- Method Quickref -->
|
65
|
+
<div id="method-list-section" class="nav-section">
|
66
|
+
<h3>Methods</h3>
|
67
|
+
|
68
|
+
<ul class="link-list" role="directory">
|
69
|
+
|
70
|
+
<li ><a href="#method-c-extended">::extended</a>
|
71
|
+
|
72
|
+
<li ><a href="#method-i-expression">#expression</a>
|
73
|
+
|
74
|
+
<li ><a href="#method-i-expression-3D">#expression=</a>
|
75
|
+
|
76
|
+
<li ><a href="#method-i-has_data-3F">#has_data?</a>
|
77
|
+
|
78
|
+
<li ><a href="#method-i-initialize_ionian">#initialize_ionian</a>
|
79
|
+
|
80
|
+
<li ><a href="#method-i-on_match">#on_match</a>
|
81
|
+
|
82
|
+
<li ><a href="#method-i-purge">#purge</a>
|
83
|
+
|
84
|
+
<li ><a href="#method-i-read_match">#read_match</a>
|
85
|
+
|
86
|
+
<li ><a href="#method-i-register_observer">#register_observer</a>
|
87
|
+
|
88
|
+
<li ><a href="#method-i-run_match">#run_match</a>
|
89
|
+
|
90
|
+
<li ><a href="#method-i-unregister_observer">#unregister_observer</a>
|
91
|
+
|
92
|
+
</ul>
|
93
|
+
</div>
|
94
|
+
|
95
|
+
</div>
|
96
|
+
</nav>
|
97
|
+
|
98
|
+
<main role="main" aria-labelledby="module-Ionian::Extension::IO">
|
99
|
+
<h1 id="module-Ionian::Extension::IO" class="module">
|
100
|
+
module Ionian::Extension::IO
|
101
|
+
</h1>
|
102
|
+
|
103
|
+
<section class="description">
|
104
|
+
|
105
|
+
<p>A mixin for <a href="IO.html">IO</a> objects that allows regular expression
|
106
|
+
matching and convenient notification of received data.</p>
|
107
|
+
|
108
|
+
<p>This module was designed to be extended by instantiated objects that
|
109
|
+
implement the standard library <a href="IO.html">IO</a> class.
|
110
|
+
my_socket.extend Ionian::IO</p>
|
111
|
+
|
112
|
+
</section>
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
<section class="attribute-method-details" class="method-section">
|
126
|
+
<header>
|
127
|
+
<h3>Attributes</h3>
|
128
|
+
</header>
|
129
|
+
|
130
|
+
|
131
|
+
<div id="attribute-i-ionian_timeout" class="method-detail">
|
132
|
+
<div class="method-heading attribute-method-heading">
|
133
|
+
<span class="method-name">ionian_timeout</span><span
|
134
|
+
class="attribute-access-type">[RW]</span>
|
135
|
+
</div>
|
136
|
+
|
137
|
+
<div class="method-description">
|
138
|
+
|
139
|
+
<p>Number of seconds to attempt an <a href="IO.html">IO</a> operation before
|
140
|
+
timing out. See standard library IO::select.</p>
|
141
|
+
|
142
|
+
</div>
|
143
|
+
</div>
|
144
|
+
|
145
|
+
</section>
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
|
150
|
+
<header>
|
151
|
+
<h3>Public Class Methods</h3>
|
152
|
+
</header>
|
153
|
+
|
154
|
+
|
155
|
+
<div id="method-c-extended" class="method-detail ">
|
156
|
+
|
157
|
+
<div class="method-heading">
|
158
|
+
<span class="method-name">extended</span><span
|
159
|
+
class="method-args">(obj)</span>
|
160
|
+
|
161
|
+
<span class="method-click-advice">click to toggle source</span>
|
162
|
+
|
163
|
+
</div>
|
164
|
+
|
165
|
+
|
166
|
+
<div class="method-description">
|
167
|
+
|
168
|
+
<p>Called automaticallly when the object is extended with extend.</p>
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
<div class="method-source-code" id="extended-source">
|
174
|
+
<pre><span class="ruby-comment"># File lib/ionian/extension/io.rb, line 15</span>
|
175
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">extended</span>(<span class="ruby-identifier">obj</span>)
|
176
|
+
<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">initialize_ionian</span>
|
177
|
+
<span class="ruby-keyword">end</span></pre>
|
178
|
+
</div>
|
179
|
+
|
180
|
+
</div>
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
</div>
|
186
|
+
|
187
|
+
|
188
|
+
</section>
|
189
|
+
|
190
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
191
|
+
<header>
|
192
|
+
<h3>Public Instance Methods</h3>
|
193
|
+
</header>
|
194
|
+
|
195
|
+
|
196
|
+
<div id="method-i-expression" class="method-detail ">
|
197
|
+
|
198
|
+
<div class="method-heading">
|
199
|
+
<span class="method-name">expression</span><span
|
200
|
+
class="method-args">()</span>
|
201
|
+
|
202
|
+
<span class="method-click-advice">click to toggle source</span>
|
203
|
+
|
204
|
+
</div>
|
205
|
+
|
206
|
+
|
207
|
+
<div class="method-description">
|
208
|
+
|
209
|
+
<p>Returns the regular expression used for <a
|
210
|
+
href="IO.html#method-i-read_match">read_match</a>.</p>
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
<div class="method-source-code" id="expression-source">
|
216
|
+
<pre><span class="ruby-comment"># File lib/ionian/extension/io.rb, line 39</span>
|
217
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">expression</span>
|
218
|
+
<span class="ruby-ivar">@ionian_expression</span>
|
219
|
+
<span class="ruby-keyword">end</span></pre>
|
220
|
+
</div>
|
221
|
+
|
222
|
+
</div>
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
</div>
|
228
|
+
|
229
|
+
|
230
|
+
<div id="method-i-expression-3D" class="method-detail ">
|
231
|
+
|
232
|
+
<div class="method-heading">
|
233
|
+
<span class="method-name">expression=</span><span
|
234
|
+
class="method-args">(exp)</span>
|
235
|
+
|
236
|
+
<span class="method-click-advice">click to toggle source</span>
|
237
|
+
|
238
|
+
</div>
|
239
|
+
|
240
|
+
|
241
|
+
<div class="method-description">
|
242
|
+
|
243
|
+
<p>Set the expression to match against the read buffer. Can be a regular
|
244
|
+
expression specifying capture groups, or a string specifying the separator
|
245
|
+
or line terminator sequence. It is possible to use named captures in a
|
246
|
+
regex, which allows for convienient accessors like <a
|
247
|
+
href=":parameter">match</a>.</p>
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
<div class="method-source-code" id="expression-3D-source">
|
253
|
+
<pre><span class="ruby-comment"># File lib/ionian/extension/io.rb, line 49</span>
|
254
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">expression=</span>(<span class="ruby-identifier">exp</span>)
|
255
|
+
<span class="ruby-ivar">@ionian_expression</span> = <span class="ruby-identifier">exp</span>
|
256
|
+
<span class="ruby-ivar">@ionian_expression</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span> <span class="ruby-node">"(.*?)#{expression}"</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">exp</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
257
|
+
<span class="ruby-keyword">end</span></pre>
|
258
|
+
</div>
|
259
|
+
|
260
|
+
</div>
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
</div>
|
266
|
+
|
267
|
+
|
268
|
+
<div id="method-i-has_data-3F" class="method-detail ">
|
269
|
+
|
270
|
+
<div class="method-heading">
|
271
|
+
<span class="method-name">has_data?</span><span
|
272
|
+
class="method-args">(timeout: 0)</span>
|
273
|
+
|
274
|
+
<span class="method-click-advice">click to toggle source</span>
|
275
|
+
|
276
|
+
</div>
|
277
|
+
|
278
|
+
|
279
|
+
<div class="method-description">
|
280
|
+
|
281
|
+
<p>Returns true if there is data in the receive buffer. Args:</p>
|
282
|
+
|
283
|
+
<pre>Timeout: Number of seconds to wait for data until
|
284
|
+
giving up. Set to nil for blocking.</pre>
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
<div class="method-source-code" id="has_data-3F-source">
|
290
|
+
<pre><span class="ruby-comment"># File lib/ionian/extension/io.rb, line 34</span>
|
291
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">has_data?</span>(<span class="ruby-identifier">timeout</span><span class="ruby-operator">:</span> <span class="ruby-value">0</span>)
|
292
|
+
<span class="ruby-operator">::</span><span class="ruby-constant">IO</span>.<span class="ruby-identifier">select</span>([<span class="ruby-keyword">self</span>], <span class="ruby-keyword">nil</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">timeout</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>
|
293
|
+
<span class="ruby-keyword">end</span></pre>
|
294
|
+
</div>
|
295
|
+
|
296
|
+
</div>
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
</div>
|
302
|
+
|
303
|
+
|
304
|
+
<div id="method-i-initialize_ionian" class="method-detail ">
|
305
|
+
|
306
|
+
<div class="method-heading">
|
307
|
+
<span class="method-name">initialize_ionian</span><span
|
308
|
+
class="method-args">()</span>
|
309
|
+
|
310
|
+
<span class="method-click-advice">click to toggle source</span>
|
311
|
+
|
312
|
+
</div>
|
313
|
+
|
314
|
+
|
315
|
+
<div class="method-description">
|
316
|
+
|
317
|
+
<p>Initialize the <a href="../../Ionian.html">Ionian</a> instance variables.
|
318
|
+
This is called automatically if extend is called on an object.</p>
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
<div class="method-source-code" id="initialize_ionian-source">
|
324
|
+
<pre><span class="ruby-comment"># File lib/ionian/extension/io.rb, line 21</span>
|
325
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize_ionian</span>
|
326
|
+
<span class="ruby-ivar">@ionian_listeners</span> = []
|
327
|
+
<span class="ruby-ivar">@ionian_buf</span> = <span class="ruby-string">''</span>
|
328
|
+
<span class="ruby-ivar">@ionian_expression</span> = <span class="ruby-regexp">/(.*?)\n/</span>
|
329
|
+
<span class="ruby-ivar">@ionian_timeout</span> = <span class="ruby-keyword">nil</span>
|
330
|
+
<span class="ruby-ivar">@ionian_skip_select</span> = <span class="ruby-keyword">false</span>
|
331
|
+
<span class="ruby-ivar">@ionian_build_methods</span> = <span class="ruby-keyword">true</span>
|
332
|
+
<span class="ruby-keyword">end</span></pre>
|
333
|
+
</div>
|
334
|
+
|
335
|
+
</div>
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
</div>
|
341
|
+
|
342
|
+
|
343
|
+
<div id="method-i-on_match" class="method-detail method-alias">
|
344
|
+
|
345
|
+
<div class="method-heading">
|
346
|
+
<span class="method-name">on_match</span><span
|
347
|
+
class="method-args">(&block)</span>
|
348
|
+
|
349
|
+
</div>
|
350
|
+
|
351
|
+
|
352
|
+
<div class="method-description">
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
</div>
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
<div class="aliases">
|
365
|
+
Alias for: <a href="IO.html#method-i-register_observer">register_observer</a>
|
366
|
+
</div>
|
367
|
+
|
368
|
+
</div>
|
369
|
+
|
370
|
+
|
371
|
+
<div id="method-i-purge" class="method-detail ">
|
372
|
+
|
373
|
+
<div class="method-heading">
|
374
|
+
<span class="method-name">purge</span><span
|
375
|
+
class="method-args">()</span>
|
376
|
+
|
377
|
+
<span class="method-click-advice">click to toggle source</span>
|
378
|
+
|
379
|
+
</div>
|
380
|
+
|
381
|
+
|
382
|
+
<div class="method-description">
|
383
|
+
|
384
|
+
<p>Erase the data in the <a href="IO.html">IO</a> and <a
|
385
|
+
href="../../Ionian.html">Ionian</a> buffers. This is typically handled
|
386
|
+
automatically.</p>
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
<div class="method-source-code" id="purge-source">
|
392
|
+
<pre><span class="ruby-comment"># File lib/ionian/extension/io.rb, line 137</span>
|
393
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">purge</span>
|
394
|
+
<span class="ruby-comment"># Erase IO buffer.</span>
|
395
|
+
<span class="ruby-keyword">while</span> <span class="ruby-operator">::</span><span class="ruby-constant">IO</span>.<span class="ruby-identifier">select</span> [<span class="ruby-keyword">self</span>], <span class="ruby-keyword">nil</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-value">0</span>
|
396
|
+
<span class="ruby-identifier">readpartial</span>(<span class="ruby-value">0xFFFF</span>)
|
397
|
+
<span class="ruby-keyword">end</span>
|
398
|
+
|
399
|
+
<span class="ruby-ivar">@ionian_buf</span> = <span class="ruby-string">''</span>
|
400
|
+
<span class="ruby-keyword">end</span></pre>
|
401
|
+
</div>
|
402
|
+
|
403
|
+
</div>
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
</div>
|
409
|
+
|
410
|
+
|
411
|
+
<div id="method-i-read_match" class="method-detail ">
|
412
|
+
|
413
|
+
<div class="method-heading">
|
414
|
+
<span class="method-name">read_match</span><span
|
415
|
+
class="method-args">(**kvargs) { |$~| ... }</span>
|
416
|
+
|
417
|
+
<span class="method-click-advice">click to toggle source</span>
|
418
|
+
|
419
|
+
</div>
|
420
|
+
|
421
|
+
|
422
|
+
<div class="method-description">
|
423
|
+
|
424
|
+
<p>Read matched data from the buffer. This method SHOULD NOT be used if <a
|
425
|
+
href="IO.html#method-i-run_match">run_match</a> is used.</p>
|
426
|
+
|
427
|
+
<p>Passes matches to the block (do |match|). If there are multiple matches,
|
428
|
+
the block is called multiple times.</p>
|
429
|
+
|
430
|
+
<p>Returns an array of matches. Returns nil if no data was received within the
|
431
|
+
timeout period.</p>
|
432
|
+
|
433
|
+
<p>Junk data that could exist before a match in the buffer can be accessed
|
434
|
+
with match.pre_match.</p>
|
435
|
+
|
436
|
+
<p>Data at the end of the buffer that is not matched can be accessed in the
|
437
|
+
last match with match.post_match. This data remains in the buffer for the
|
438
|
+
next <a href="IO.html#method-i-read_match">read_match</a> cycle. This is
|
439
|
+
helpful for protocols like RS232 that do not have packet boundries.</p>
|
440
|
+
|
441
|
+
<p>kvargs:</p>
|
442
|
+
|
443
|
+
<pre>timeout: Timeout in seconds IO::select will block.
|
444
|
+
skip_select: Skip over the IO::select statement. Use if you
|
445
|
+
are calling IO::select ahead of this method.
|
446
|
+
build_methods: Build method accessors from named captures.
|
447
|
+
Enabled by default.</pre>
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
<div class="method-source-code" id="read_match-source">
|
453
|
+
<pre><span class="ruby-comment"># File lib/ionian/extension/io.rb, line 77</span>
|
454
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_match</span>(<span class="ruby-operator">**</span><span class="ruby-identifier">kvargs</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
455
|
+
<span class="ruby-identifier">timeout</span> = <span class="ruby-identifier">kvargs</span>.<span class="ruby-identifier">fetch</span> <span class="ruby-value">:timeout</span>, <span class="ruby-ivar">@ionian_timeout</span>
|
456
|
+
<span class="ruby-identifier">skip_select</span> = <span class="ruby-identifier">kvargs</span>.<span class="ruby-identifier">fetch</span> <span class="ruby-value">:skip_select</span>, <span class="ruby-ivar">@ionian_skip_select</span>
|
457
|
+
<span class="ruby-identifier">build_methods</span> = <span class="ruby-identifier">kvargs</span>.<span class="ruby-identifier">fetch</span> <span class="ruby-value">:build_methods</span>, <span class="ruby-ivar">@ionian_build_methods</span>
|
458
|
+
|
459
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">skip_select</span>
|
460
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">unless</span> <span class="ruby-operator">::</span><span class="ruby-constant">IO</span>.<span class="ruby-identifier">select</span> [<span class="ruby-keyword">self</span>], <span class="ruby-keyword">nil</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">timeout</span>
|
461
|
+
<span class="ruby-keyword">end</span>
|
462
|
+
|
463
|
+
<span class="ruby-comment"># Read data from the IO buffer until it's empty.</span>
|
464
|
+
<span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span>
|
465
|
+
<span class="ruby-ivar">@ionian_buf</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">readpartial</span>(<span class="ruby-value">0xFFFF</span>)
|
466
|
+
<span class="ruby-keyword">break</span> <span class="ruby-keyword">unless</span> <span class="ruby-operator">::</span><span class="ruby-constant">IO</span>.<span class="ruby-identifier">select</span> [<span class="ruby-keyword">self</span>], <span class="ruby-keyword">nil</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-value">0</span>
|
467
|
+
<span class="ruby-keyword">end</span>
|
468
|
+
|
469
|
+
<span class="ruby-ivar">@matches</span> = []
|
470
|
+
|
471
|
+
<span class="ruby-keyword">while</span> <span class="ruby-ivar">@ionian_buf</span> <span class="ruby-operator">=~</span> <span class="ruby-ivar">@ionian_expression</span>
|
472
|
+
<span class="ruby-ivar">@matches</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">$~</span> <span class="ruby-comment"># Match data.</span>
|
473
|
+
<span class="ruby-keyword">yield</span> <span class="ruby-identifier">$~</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
|
474
|
+
<span class="ruby-ivar">@ionian_buf</span> = <span class="ruby-node">$'</span> <span class="ruby-comment"># Leave post match data in the buffer.</span>
|
475
|
+
<span class="ruby-keyword">end</span>
|
476
|
+
|
477
|
+
<span class="ruby-comment"># Convert named captures to methods.</span>
|
478
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">build_methods</span>
|
479
|
+
<span class="ruby-ivar">@matches</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
|
480
|
+
<span class="ruby-identifier">match</span>.<span class="ruby-identifier">names</span>
|
481
|
+
.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>}
|
482
|
+
.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">symbol</span><span class="ruby-operator">|</span> <span class="ruby-identifier">match</span>.<span class="ruby-identifier">singleton_class</span>
|
483
|
+
.<span class="ruby-identifier">send</span>(<span class="ruby-value">:define_method</span>, <span class="ruby-identifier">symbol</span>) { <span class="ruby-identifier">match</span>[<span class="ruby-identifier">symbol</span>] } <span class="ruby-keyword">unless</span> <span class="ruby-identifier">match</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">symbol</span>
|
484
|
+
}
|
485
|
+
<span class="ruby-keyword">end</span>
|
486
|
+
<span class="ruby-keyword">end</span>
|
487
|
+
|
488
|
+
<span class="ruby-ivar">@matches</span>
|
489
|
+
<span class="ruby-keyword">end</span></pre>
|
490
|
+
</div>
|
491
|
+
|
492
|
+
</div>
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
</div>
|
498
|
+
|
499
|
+
|
500
|
+
<div id="method-i-register_observer" class="method-detail ">
|
501
|
+
|
502
|
+
<div class="method-heading">
|
503
|
+
<span class="method-name">register_observer</span><span
|
504
|
+
class="method-args">(&block)</span>
|
505
|
+
|
506
|
+
<span class="method-click-advice">click to toggle source</span>
|
507
|
+
|
508
|
+
</div>
|
509
|
+
|
510
|
+
|
511
|
+
<div class="method-description">
|
512
|
+
|
513
|
+
<p>Register a block to be called when <a
|
514
|
+
href="IO.html#method-i-run_match">run_match</a> receives matched data.
|
515
|
+
Method callbacks can be registered with &object.method(:method).
|
516
|
+
Returns a reference to the given block. block =
|
517
|
+
ionian_socket.register_observer {…}</p>
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
|
522
|
+
<div class="method-source-code" id="register_observer-source">
|
523
|
+
<pre><span class="ruby-comment"># File lib/ionian/extension/io.rb, line 150</span>
|
524
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">register_observer</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
525
|
+
<span class="ruby-ivar">@ionian_listeners</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@ionian_listeners</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">block</span>
|
526
|
+
<span class="ruby-identifier">block</span>
|
527
|
+
<span class="ruby-keyword">end</span></pre>
|
528
|
+
</div>
|
529
|
+
|
530
|
+
</div>
|
531
|
+
|
532
|
+
|
533
|
+
<div class="aliases">
|
534
|
+
Also aliased as: <a href="IO.html#method-i-on_match">on_match</a>
|
535
|
+
</div>
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
</div>
|
540
|
+
|
541
|
+
|
542
|
+
<div id="method-i-run_match" class="method-detail ">
|
543
|
+
|
544
|
+
<div class="method-heading">
|
545
|
+
<span class="method-name">run_match</span><span
|
546
|
+
class="method-args">(**kvargs)</span>
|
547
|
+
|
548
|
+
<span class="method-click-advice">click to toggle source</span>
|
549
|
+
|
550
|
+
</div>
|
551
|
+
|
552
|
+
|
553
|
+
<div class="method-description">
|
554
|
+
|
555
|
+
<p>Start a thread that checks for data and notifies listeners (do |match,
|
556
|
+
socket|). Passes kvargs to <a
|
557
|
+
href="IO.html#method-i-read_match">read_match</a>. This method SHOULD NOT
|
558
|
+
be used if <a href="IO.html#method-i-read_match">read_match</a> is used.</p>
|
559
|
+
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
<div class="method-source-code" id="run_match-source">
|
564
|
+
<pre><span class="ruby-comment"># File lib/ionian/extension/io.rb, line 118</span>
|
565
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">run_match</span>(<span class="ruby-operator">**</span><span class="ruby-identifier">kvargs</span>)
|
566
|
+
<span class="ruby-ivar">@match_listener</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span>
|
567
|
+
<span class="ruby-keyword">begin</span>
|
568
|
+
<span class="ruby-keyword">while</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">closed?</span> <span class="ruby-keyword">do</span>
|
569
|
+
<span class="ruby-identifier">matches</span> = <span class="ruby-identifier">read_match</span> <span class="ruby-identifier">kvargs</span>
|
570
|
+
<span class="ruby-identifier">matches</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
|
571
|
+
<span class="ruby-ivar">@ionian_listeners</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">listener</span><span class="ruby-operator">|</span> <span class="ruby-identifier">listener</span>.<span class="ruby-identifier">call</span> <span class="ruby-identifier">match</span>, <span class="ruby-keyword">self</span>}
|
572
|
+
} <span class="ruby-keyword">if</span> <span class="ruby-identifier">matches</span>
|
573
|
+
<span class="ruby-keyword">end</span>
|
574
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">EOFError</span>
|
575
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">IOError</span>
|
576
|
+
<span class="ruby-keyword">ensure</span>
|
577
|
+
<span class="ruby-ivar">@match_listener</span> = <span class="ruby-keyword">nil</span>
|
578
|
+
<span class="ruby-keyword">end</span>
|
579
|
+
<span class="ruby-keyword">end</span>
|
580
|
+
<span class="ruby-keyword">end</span></pre>
|
581
|
+
</div>
|
582
|
+
|
583
|
+
</div>
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
|
588
|
+
</div>
|
589
|
+
|
590
|
+
|
591
|
+
<div id="method-i-unregister_observer" class="method-detail ">
|
592
|
+
|
593
|
+
<div class="method-heading">
|
594
|
+
<span class="method-name">unregister_observer</span><span
|
595
|
+
class="method-args">(&block)</span>
|
596
|
+
|
597
|
+
<span class="method-click-advice">click to toggle source</span>
|
598
|
+
|
599
|
+
</div>
|
600
|
+
|
601
|
+
|
602
|
+
<div class="method-description">
|
603
|
+
|
604
|
+
<p>Unregister a block from being called when matched data is received.</p>
|
605
|
+
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
<div class="method-source-code" id="unregister_observer-source">
|
610
|
+
<pre><span class="ruby-comment"># File lib/ionian/extension/io.rb, line 158</span>
|
611
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">unregister_observer</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
612
|
+
<span class="ruby-ivar">@ionian_listeners</span>.<span class="ruby-identifier">delete_if</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span> <span class="ruby-identifier">o</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">block</span>}
|
613
|
+
<span class="ruby-identifier">block</span>
|
614
|
+
<span class="ruby-keyword">end</span></pre>
|
615
|
+
</div>
|
616
|
+
|
617
|
+
</div>
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
|
622
|
+
</div>
|
623
|
+
|
624
|
+
|
625
|
+
</section>
|
626
|
+
|
627
|
+
</section>
|
628
|
+
</main>
|
629
|
+
|
630
|
+
|
631
|
+
<footer id="validator-badges" role="contentinfo">
|
632
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
633
|
+
<p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.0.preview.1.
|
634
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
635
|
+
</footer>
|
636
|
+
|