elster 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. data/Users/jwebb/src/bigjason/elster/Gemfile +4 -0
  2. data/Users/jwebb/src/bigjason/elster/Gemfile.lock +30 -0
  3. data/Users/jwebb/src/bigjason/elster/LICENSE +22 -0
  4. data/Users/jwebb/src/bigjason/elster/README.md +39 -0
  5. data/Users/jwebb/src/bigjason/elster/Rakefile +2 -0
  6. data/Users/jwebb/src/bigjason/elster/doc/Elster/Streamer.html +526 -0
  7. data/Users/jwebb/src/bigjason/elster/doc/Elster.html +129 -0
  8. data/Users/jwebb/src/bigjason/elster/doc/_index.html +125 -0
  9. data/Users/jwebb/src/bigjason/elster/doc/class_list.html +53 -0
  10. data/Users/jwebb/src/bigjason/elster/doc/css/common.css +1 -0
  11. data/Users/jwebb/src/bigjason/elster/doc/css/full_list.css +57 -0
  12. data/Users/jwebb/src/bigjason/elster/doc/css/style.css +328 -0
  13. data/Users/jwebb/src/bigjason/elster/doc/file.README.html +107 -0
  14. data/Users/jwebb/src/bigjason/elster/doc/file_list.html +55 -0
  15. data/Users/jwebb/src/bigjason/elster/doc/frames.html +28 -0
  16. data/Users/jwebb/src/bigjason/elster/doc/index.html +107 -0
  17. data/Users/jwebb/src/bigjason/elster/doc/js/app.js +214 -0
  18. data/Users/jwebb/src/bigjason/elster/doc/js/full_list.js +173 -0
  19. data/Users/jwebb/src/bigjason/elster/doc/js/jquery.js +4 -0
  20. data/Users/jwebb/src/bigjason/elster/doc/method_list.html +84 -0
  21. data/Users/jwebb/src/bigjason/elster/doc/top-level-namespace.html +112 -0
  22. data/Users/jwebb/src/bigjason/elster/elster.gemspec +21 -0
  23. data/Users/jwebb/src/bigjason/elster/lib/elster/streamer.rb +145 -0
  24. data/Users/jwebb/src/bigjason/elster/lib/elster/version.rb +3 -0
  25. data/Users/jwebb/src/bigjason/elster/lib/elster.rb +2 -0
  26. data/Users/jwebb/src/bigjason/elster/test/streamer_test.rb +117 -0
  27. metadata +116 -0
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in elster.gemspec
4
+ gemspec
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ elster (0.0.2)
5
+ multi_json
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ansi (1.4.0)
11
+ coderay (1.0.7)
12
+ method_source (0.8)
13
+ minitest (3.3.0)
14
+ multi_json (1.3.6)
15
+ pry (0.9.10)
16
+ coderay (~> 1.0.5)
17
+ method_source (~> 0.8)
18
+ slop (~> 3.3.1)
19
+ slop (3.3.2)
20
+ turn (0.8.3)
21
+ ansi
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ elster!
28
+ minitest
29
+ pry
30
+ turn
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jason Webb
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Elster
2
+
3
+ A simple streaming JSON encoder.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'elster'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install elster
18
+
19
+ ## Usage
20
+
21
+ output = StringIO.new
22
+ json = Elster::Streamer.new(output)
23
+ json.key(:name, "George")
24
+ json.key(:kids) do
25
+ json.add("Job")
26
+ json.add("Buster")
27
+ end
28
+ json.close
29
+
30
+ puts output.string
31
+ # {"name":"George","kids":["Job","Buster"]}
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,526 @@
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: Elster::Streamer
8
+
9
+ &mdash; Documentation by YARD 0.8.2.1
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" 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#!" + escape(window.location.href);
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 (S)</a> &raquo;
35
+ <span class='title'><span class='object_link'><a href="../Elster.html" title="Elster (module)">Elster</a></span></span>
36
+ &raquo;
37
+ <span class="title">Streamer</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: Elster::Streamer
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">Elster::Streamer</li>
82
+
83
+ </ul>
84
+ <a href="#" class="inheritanceTree">show all</a>
85
+
86
+ </dd>
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+ <dt class="r2 last">Defined in:</dt>
97
+ <dd class="r2 last">lib/elster/streamer.rb</dd>
98
+
99
+ </dl>
100
+ <div class="clear"></div>
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ <h2>
111
+ Instance Method Summary
112
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
113
+ </h2>
114
+
115
+ <ul class="summary">
116
+
117
+ <li class="public ">
118
+ <span class="summary_signature">
119
+
120
+ <a href="#add-instance_method" title="#add (instance method)">- (Object) <strong>add</strong>(value = nil, &amp;block) </a>
121
+
122
+
123
+
124
+ </span>
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+ <span class="summary_desc"><div class='inline'><p>
135
+ Output an array.
136
+ </p>
137
+ </div></span>
138
+
139
+ </li>
140
+
141
+
142
+ <li class="public ">
143
+ <span class="summary_signature">
144
+
145
+ <a href="#close-instance_method" title="#close (instance method)">- (Object) <strong>close</strong>(close_stream = false) </a>
146
+
147
+
148
+
149
+ </span>
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+ <span class="summary_desc"><div class='inline'><p>
160
+ Close the encoding optionally closing the provided output stream.
161
+ </p>
162
+ </div></span>
163
+
164
+ </li>
165
+
166
+
167
+ <li class="public ">
168
+ <span class="summary_signature">
169
+
170
+ <a href="#initialize-instance_method" title="#initialize (instance method)">- (Streamer) <strong>initialize</strong>(output) </a>
171
+
172
+
173
+
174
+ </span>
175
+
176
+
177
+ <span class="note title constructor">constructor</span>
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+ <span class="summary_desc"><div class='inline'><p>
187
+ Create a new instance of Streamer with the specified output stream.
188
+ </p>
189
+ </div></span>
190
+
191
+ </li>
192
+
193
+
194
+ <li class="public ">
195
+ <span class="summary_signature">
196
+
197
+ <a href="#key-instance_method" title="#key (instance method)">- (Object) <strong>key</strong>(key, value = nil, &amp;block) </a>
198
+
199
+
200
+
201
+ </span>
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+ <span class="summary_desc"><div class='inline'><p>
212
+ Output an object key value pair.
213
+ </p>
214
+ </div></span>
215
+
216
+ </li>
217
+
218
+
219
+ </ul>
220
+
221
+
222
+ <div id="constructor_details" class="method_details_list">
223
+ <h2>Constructor Details</h2>
224
+
225
+ <div class="method_details first">
226
+ <h3 class="signature first" id="initialize-instance_method">
227
+
228
+ - (<tt><span class='object_link'><a href="" title="Elster::Streamer (class)">Streamer</a></span></tt>) <strong>initialize</strong>(output)
229
+
230
+
231
+
232
+
233
+
234
+ </h3><div class="docstring">
235
+ <div class="discussion">
236
+ <p>
237
+ Create a new instance of Streamer with the specified output stream. The
238
+ `output` must respond to `write`.
239
+ </p>
240
+
241
+
242
+ </div>
243
+ </div>
244
+ <div class="tags">
245
+
246
+
247
+ </div><table class="source_code">
248
+ <tr>
249
+ <td>
250
+ <pre class="lines">
251
+
252
+
253
+ 8
254
+ 9
255
+ 10
256
+ 11
257
+ 12
258
+ 13</pre>
259
+ </td>
260
+ <td>
261
+ <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 8</span>
262
+
263
+ <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_output'>output</span><span class='rparen'>)</span>
264
+ <span class='ivar'>@output</span> <span class='op'>=</span> <span class='id identifier rubyid_output'>output</span>
265
+ <span class='comment'># Some mutable state to make Rich Hickey weep.
266
+ </span> <span class='ivar'>@stack</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
267
+ <span class='ivar'>@item_count</span> <span class='op'>=</span> <span class='int'>0</span>
268
+ <span class='kw'>end</span></pre>
269
+ </td>
270
+ </tr>
271
+ </table>
272
+ </div>
273
+
274
+ </div>
275
+
276
+
277
+ <div id="instance_method_details" class="method_details_list">
278
+ <h2>Instance Method Details</h2>
279
+
280
+
281
+ <div class="method_details first">
282
+ <h3 class="signature first" id="add-instance_method">
283
+
284
+ - (<tt>Object</tt>) <strong>add</strong>(value = nil, &amp;block)
285
+
286
+
287
+
288
+
289
+
290
+ </h3><div class="docstring">
291
+ <div class="discussion">
292
+ <p>
293
+ Output an array. If a block is passes the `value` will be ignored and a
294
+ nested value started.
295
+ </p>
296
+ <p>
297
+ Example:
298
+ </p>
299
+ <pre class="code ruby"><code>
300
+ json.add(1)
301
+ json.add(&quot;Ansible&quot;)
302
+
303
+ [ 1, &quot;Ansible&quot; ]
304
+
305
+ json.add(1)
306
+ json.add do
307
+ json.set(:name, &quot;Wiggens&quot;)
308
+ end
309
+
310
+ [ 1, { &quot;name&quot; : &quot;Wiggens&quot; } ]</code></pre>
311
+
312
+
313
+ </div>
314
+ </div>
315
+ <div class="tags">
316
+
317
+
318
+ </div><table class="source_code">
319
+ <tr>
320
+ <td>
321
+ <pre class="lines">
322
+
323
+
324
+ 83
325
+ 84
326
+ 85
327
+ 86
328
+ 87
329
+ 88
330
+ 89
331
+ 90
332
+ 91
333
+ 92
334
+ 93
335
+ 94
336
+ 95
337
+ 96
338
+ 97
339
+ 98
340
+ 99
341
+ 100</pre>
342
+ </td>
343
+ <td>
344
+ <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 83</span>
345
+
346
+ <span class='kw'>def</span> <span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='op'>=</span><span class='kw'>nil</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
347
+ <span class='kw'>if</span> <span class='ivar'>@item_count</span> <span class='op'>&gt;</span> <span class='int'>0</span>
348
+ <span class='id identifier rubyid_write'>write</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>,</span><span class='tstring_end'>&quot;</span></span>
349
+ <span class='kw'>else</span>
350
+ <span class='ivar'>@current_type</span> <span class='op'>=</span> <span class='symbol'>:array</span>
351
+ <span class='id identifier rubyid_begin_section'>begin_section</span>
352
+ <span class='kw'>end</span>
353
+
354
+ <span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span>
355
+ <span class='id identifier rubyid_nest_in'>nest_in</span>
356
+ <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
357
+ <span class='id identifier rubyid_nest_out'>nest_out</span>
358
+ <span class='kw'>else</span>
359
+ <span class='id identifier rubyid_write'>write</span> <span class='id identifier rubyid_encode_value'>encode_value</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
360
+ <span class='kw'>end</span>
361
+
362
+ <span class='ivar'>@item_count</span> <span class='op'>+=</span> <span class='int'>1</span>
363
+ <span class='kw'>end</span></pre>
364
+ </td>
365
+ </tr>
366
+ </table>
367
+ </div>
368
+
369
+ <div class="method_details ">
370
+ <h3 class="signature " id="close-instance_method">
371
+
372
+ - (<tt>Object</tt>) <strong>close</strong>(close_stream = false)
373
+
374
+
375
+
376
+
377
+
378
+ </h3><div class="docstring">
379
+ <div class="discussion">
380
+ <p>
381
+ Close the encoding optionally closing the provided output stream.
382
+ </p>
383
+
384
+
385
+ </div>
386
+ </div>
387
+ <div class="tags">
388
+
389
+
390
+ </div><table class="source_code">
391
+ <tr>
392
+ <td>
393
+ <pre class="lines">
394
+
395
+
396
+ 16
397
+ 17
398
+ 18
399
+ 19
400
+ 20
401
+ 21</pre>
402
+ </td>
403
+ <td>
404
+ <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 16</span>
405
+
406
+ <span class='kw'>def</span> <span class='id identifier rubyid_close'>close</span><span class='lparen'>(</span><span class='id identifier rubyid_close_stream'>close_stream</span><span class='op'>=</span><span class='kw'>false</span><span class='rparen'>)</span>
407
+ <span class='id identifier rubyid_end_section'>end_section</span>
408
+ <span class='kw'>if</span> <span class='id identifier rubyid_close_stream'>close_stream</span>
409
+ <span class='ivar'>@output</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
410
+ <span class='kw'>end</span>
411
+ <span class='kw'>end</span></pre>
412
+ </td>
413
+ </tr>
414
+ </table>
415
+ </div>
416
+
417
+ <div class="method_details ">
418
+ <h3 class="signature " id="key-instance_method">
419
+
420
+ - (<tt>Object</tt>) <strong>key</strong>(key, value = nil, &amp;block)
421
+
422
+
423
+
424
+
425
+
426
+ </h3><div class="docstring">
427
+ <div class="discussion">
428
+ <p>
429
+ Output an object key value pair. If a block is passed, the `value` will be
430
+ ignored and a nested object or array can be added.
431
+ </p>
432
+ <p>
433
+ Example:
434
+ </p>
435
+ <pre class="code ruby"><code>
436
+ json.key(:mistake, &quot;HUGE!&quot;)
437
+
438
+ { &quot;mistake&quot; : &quot;HUGE!&quot; }
439
+
440
+ json.key(:mistake) do
441
+ json.key(:type, &quot;HUGE!&quot;)
442
+ end
443
+
444
+ { &quot;mistake&quot; : { &quot;type&quot; : &quot;HUGE!&quot; } }
445
+
446
+ json.key(:mistake) do
447
+ json.add(&quot;HUGE!&quot;)
448
+ end
449
+
450
+ { &quot;mistake&quot; : [ &quot;HUGE!&quot; ] }</code></pre>
451
+
452
+
453
+ </div>
454
+ </div>
455
+ <div class="tags">
456
+
457
+
458
+ </div><table class="source_code">
459
+ <tr>
460
+ <td>
461
+ <pre class="lines">
462
+
463
+
464
+ 45
465
+ 46
466
+ 47
467
+ 48
468
+ 49
469
+ 50
470
+ 51
471
+ 52
472
+ 53
473
+ 54
474
+ 55
475
+ 56
476
+ 57
477
+ 58
478
+ 59
479
+ 60
480
+ 61
481
+ 62
482
+ 63
483
+ 64
484
+ 65</pre>
485
+ </td>
486
+ <td>
487
+ <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 45</span>
488
+
489
+ <span class='kw'>def</span> <span class='id identifier rubyid_key'>key</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>=</span><span class='kw'>nil</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
490
+ <span class='kw'>if</span> <span class='ivar'>@item_count</span> <span class='op'>&gt;</span> <span class='int'>0</span>
491
+ <span class='id identifier rubyid_write'>write</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>,</span><span class='tstring_end'>&quot;</span></span>
492
+ <span class='kw'>else</span>
493
+ <span class='ivar'>@current_type</span> <span class='op'>=</span> <span class='symbol'>:object</span>
494
+ <span class='id identifier rubyid_begin_section'>begin_section</span>
495
+ <span class='kw'>end</span>
496
+
497
+ <span class='id identifier rubyid_write'>write</span> <span class='id identifier rubyid_encode_value'>encode_value</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
498
+ <span class='id identifier rubyid_write'>write</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>:</span><span class='tstring_end'>&quot;</span></span>
499
+
500
+ <span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span>
501
+ <span class='id identifier rubyid_nest_in'>nest_in</span>
502
+ <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
503
+ <span class='id identifier rubyid_nest_out'>nest_out</span>
504
+ <span class='kw'>else</span>
505
+ <span class='id identifier rubyid_write'>write</span> <span class='id identifier rubyid_encode_value'>encode_value</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
506
+ <span class='kw'>end</span>
507
+
508
+ <span class='ivar'>@item_count</span> <span class='op'>+=</span> <span class='int'>1</span>
509
+ <span class='kw'>end</span></pre>
510
+ </td>
511
+ </tr>
512
+ </table>
513
+ </div>
514
+
515
+ </div>
516
+
517
+ </div>
518
+
519
+ <div id="footer">
520
+ Generated on Sun Aug 19 23:07:22 2012 by
521
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
522
+ 0.8.2.1 (ruby-1.9.2).
523
+ </div>
524
+
525
+ </body>
526
+ </html>