elster 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elster (0.0.7)
4
+ elster (0.0.8)
5
5
  multi_json
6
6
 
7
7
  GEM
@@ -11,7 +11,7 @@ GEM
11
11
  coderay (1.0.7)
12
12
  method_source (0.8)
13
13
  minitest (3.3.0)
14
- multi_json (1.3.6)
14
+ multi_json (1.3.7)
15
15
  pry (0.9.10)
16
16
  coderay (~> 1.0.5)
17
17
  method_source (~> 0.8)
@@ -80,7 +80,7 @@
80
80
 
81
81
  <dt class="r1 last">Defined in:</dt>
82
82
  <dd class="r1 last">lib/elster/version.rb<span class="defines">,<br />
83
- lib/elster/streamer.rb</span>
83
+ lib/elster/streamer.rb,<br /> lib/elster/exceptions.rb</span>
84
84
  </dd>
85
85
 
86
86
  </dl>
@@ -92,7 +92,7 @@
92
92
 
93
93
 
94
94
 
95
- <strong class="classes">Classes:</strong> <span class='object_link'><a href="Elster/Streamer.html" title="Elster::Streamer (class)">Streamer</a></span>
95
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="Elster/JsonContainerTypeError.html" title="Elster::JsonContainerTypeError (class)">JsonContainerTypeError</a></span>, <span class='object_link'><a href="Elster/Streamer.html" title="Elster::Streamer (class)">Streamer</a></span>
96
96
 
97
97
 
98
98
  </p>
@@ -104,7 +104,7 @@
104
104
  <dt id="VERSION-constant" class="">VERSION =
105
105
 
106
106
  </dt>
107
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.0.2</span><span class='tstring_end'>&quot;</span></span></pre></dd>
107
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.0.7</span><span class='tstring_end'>&quot;</span></span></pre></dd>
108
108
 
109
109
  </dl>
110
110
 
@@ -120,9 +120,9 @@
120
120
  </div>
121
121
 
122
122
  <div id="footer">
123
- Generated on Sun Aug 19 23:07:22 2012 by
123
+ Generated on Tue Aug 21 21:31:10 2012 by
124
124
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
125
- 0.8.2.1 (ruby-1.9.2).
125
+ 0.8.2.1 (ruby-1.9.3).
126
126
  </div>
127
127
 
128
128
  </body>
@@ -0,0 +1,123 @@
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
+ Exception: Elster::JsonContainerTypeError
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 (J)</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">JsonContainerTypeError</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>Exception: Elster::JsonContainerTypeError
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">StandardError</span>
77
+
78
+ <ul class="fullTree">
79
+ <li>Object</li>
80
+
81
+ <li class="next">StandardError</li>
82
+
83
+ <li class="next">Elster::JsonContainerTypeError</li>
84
+
85
+ </ul>
86
+ <a href="#" class="inheritanceTree">show all</a>
87
+
88
+ </dd>
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+ <dt class="r2 last">Defined in:</dt>
99
+ <dd class="r2 last">lib/elster/exceptions.rb</dd>
100
+
101
+ </dl>
102
+ <div class="clear"></div>
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+ </div>
115
+
116
+ <div id="footer">
117
+ Generated on Tue Aug 21 21:31:10 2012 by
118
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
119
+ 0.8.2.1 (ruby-1.9.3).
120
+ </div>
121
+
122
+ </body>
123
+ </html>
@@ -100,10 +100,46 @@
100
100
  <div class="clear"></div>
101
101
 
102
102
 
103
+ <h2>Constant Summary</h2>
104
+
103
105
 
104
106
 
105
107
 
106
108
 
109
+ <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
110
+ <ul class="summary">
111
+
112
+ <li class="public ">
113
+ <span class="summary_signature">
114
+
115
+ <a href="#output-instance_method" title="#output (instance method)">- (Object) <strong>output</strong> </a>
116
+
117
+
118
+
119
+ </span>
120
+
121
+
122
+
123
+
124
+ <span class="note title readonly">readonly</span>
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+ <span class="summary_desc"><div class='inline'><p>Returns the value of attribute output.</p>
135
+ </div></span>
136
+
137
+ </li>
138
+
139
+
140
+ </ul>
141
+
142
+
107
143
 
108
144
 
109
145
 
@@ -131,9 +167,7 @@
131
167
 
132
168
 
133
169
 
134
- <span class="summary_desc"><div class='inline'><p>
135
- Output an array.
136
- </p>
170
+ <span class="summary_desc"><div class='inline'><p>Output an array.</p>
137
171
  </div></span>
138
172
 
139
173
  </li>
@@ -156,9 +190,7 @@ Output an array.
156
190
 
157
191
 
158
192
 
159
- <span class="summary_desc"><div class='inline'><p>
160
- Close the encoding optionally closing the provided output stream.
161
- </p>
193
+ <span class="summary_desc"><div class='inline'><p>Close the encoding optionally closing the provided output stream.</p>
162
194
  </div></span>
163
195
 
164
196
  </li>
@@ -183,9 +215,7 @@ Close the encoding optionally closing the provided output stream.
183
215
 
184
216
 
185
217
 
186
- <span class="summary_desc"><div class='inline'><p>
187
- Create a new instance of Streamer with the specified output stream.
188
- </p>
218
+ <span class="summary_desc"><div class='inline'><p>Create a new instance of Streamer with the specified output stream.</p>
189
219
  </div></span>
190
220
 
191
221
  </li>
@@ -208,9 +238,7 @@ Create a new instance of Streamer with the specified output stream.
208
238
 
209
239
 
210
240
 
211
- <span class="summary_desc"><div class='inline'><p>
212
- Output an object key value pair.
213
- </p>
241
+ <span class="summary_desc"><div class='inline'><p>Output an object key value pair.</p>
214
242
  </div></span>
215
243
 
216
244
  </li>
@@ -233,10 +261,8 @@ Output an object key value pair.
233
261
 
234
262
  </h3><div class="docstring">
235
263
  <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>
264
+ <p>Create a new instance of Streamer with the specified output stream. The
265
+ <code>output</code> must respond to <code>write</code>.</p>
240
266
 
241
267
 
242
268
  </div>
@@ -250,15 +276,15 @@ Create a new instance of Streamer with the specified output stream. The
250
276
  <pre class="lines">
251
277
 
252
278
 
253
- 8
254
279
  9
255
280
  10
256
281
  11
257
282
  12
258
- 13</pre>
283
+ 13
284
+ 14</pre>
259
285
  </td>
260
286
  <td>
261
- <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 8</span>
287
+ <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 9</span>
262
288
 
263
289
  <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
290
  <span class='ivar'>@output</span> <span class='op'>=</span> <span class='id identifier rubyid_output'>output</span>
@@ -273,6 +299,53 @@ Create a new instance of Streamer with the specified output stream. The
273
299
 
274
300
  </div>
275
301
 
302
+ <div id="instance_attr_details" class="attr_details">
303
+ <h2>Instance Attribute Details</h2>
304
+
305
+
306
+ <span id=""></span>
307
+ <div class="method_details first">
308
+ <h3 class="signature first" id="output-instance_method">
309
+
310
+ - (<tt>Object</tt>) <strong>output</strong> <span class="extras">(readonly)</span>
311
+
312
+
313
+
314
+
315
+
316
+ </h3><div class="docstring">
317
+ <div class="discussion">
318
+ <p>Returns the value of attribute output</p>
319
+
320
+
321
+ </div>
322
+ </div>
323
+ <div class="tags">
324
+
325
+
326
+ </div><table class="source_code">
327
+ <tr>
328
+ <td>
329
+ <pre class="lines">
330
+
331
+
332
+ 5
333
+ 6
334
+ 7</pre>
335
+ </td>
336
+ <td>
337
+ <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 5</span>
338
+
339
+ <span class='kw'>def</span> <span class='id identifier rubyid_output'>output</span>
340
+ <span class='ivar'>@output</span>
341
+ <span class='kw'>end</span></pre>
342
+ </td>
343
+ </tr>
344
+ </table>
345
+ </div>
346
+
347
+ </div>
348
+
276
349
 
277
350
  <div id="instance_method_details" class="method_details_list">
278
351
  <h2>Instance Method Details</h2>
@@ -289,25 +362,22 @@ Create a new instance of Streamer with the specified output stream. The
289
362
 
290
363
  </h3><div class="docstring">
291
364
  <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)
365
+ <p>Output an array. If a block is passes the <code>value</code> will be ignored and a nested value
366
+ started.</p>
367
+
368
+ <p>Example:</p>
369
+
370
+ <p>json.add(1)
371
+ json.add(&quot;Ansible&quot;)</p>
372
+
373
+ <p>[ 1, &quot;Ansible&quot; ]</p>
374
+
375
+ <p>json.add(1)
306
376
  json.add do
307
377
  json.set(:name, &quot;Wiggens&quot;)
308
- end
378
+ end</p>
309
379
 
310
- [ 1, { &quot;name&quot; : &quot;Wiggens&quot; } ]</code></pre>
380
+ <p>[ 1, { &quot;name&quot; : &quot;Wiggens&quot; } ]</p>
311
381
 
312
382
 
313
383
  </div>
@@ -321,11 +391,6 @@ Example:
321
391
  <pre class="lines">
322
392
 
323
393
 
324
- 83
325
- 84
326
- 85
327
- 86
328
- 87
329
394
  88
330
395
  89
331
396
  90
@@ -338,12 +403,25 @@ Example:
338
403
  97
339
404
  98
340
405
  99
341
- 100</pre>
406
+ 100
407
+ 101
408
+ 102
409
+ 103
410
+ 104
411
+ 105
412
+ 106
413
+ 107
414
+ 108
415
+ 109</pre>
342
416
  </td>
343
417
  <td>
344
- <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 83</span>
418
+ <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 88</span>
345
419
 
346
420
  <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>
421
+ <span class='kw'>if</span> <span class='ivar'>@current_type</span> <span class='op'>==</span> <span class='symbol'>:object</span>
422
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>JsonContainerTypeError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Attempted to add an array value inside a JSON object.</span><span class='tstring_end'>&quot;</span></span>
423
+ <span class='kw'>end</span>
424
+
347
425
  <span class='kw'>if</span> <span class='ivar'>@item_count</span> <span class='op'>&gt;</span> <span class='int'>0</span>
348
426
  <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
427
  <span class='kw'>else</span>
@@ -377,9 +455,7 @@ Example:
377
455
 
378
456
  </h3><div class="docstring">
379
457
  <div class="discussion">
380
- <p>
381
- Close the encoding optionally closing the provided output stream.
382
- </p>
458
+ <p>Close the encoding optionally closing the provided output stream.</p>
383
459
 
384
460
 
385
461
  </div>
@@ -393,15 +469,15 @@ Close the encoding optionally closing the provided output stream.
393
469
  <pre class="lines">
394
470
 
395
471
 
396
- 16
397
472
  17
398
473
  18
399
474
  19
400
475
  20
401
- 21</pre>
476
+ 21
477
+ 22</pre>
402
478
  </td>
403
479
  <td>
404
- <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 16</span>
480
+ <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 17</span>
405
481
 
406
482
  <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
483
  <span class='id identifier rubyid_end_section'>end_section</span>
@@ -425,29 +501,26 @@ Close the encoding optionally closing the provided output stream.
425
501
 
426
502
  </h3><div class="docstring">
427
503
  <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;)
504
+ <p>Output an object key value pair. If a block is passed, the <code>value</code> will be
505
+ ignored and a nested object or array can be added.</p>
437
506
 
438
- { &quot;mistake&quot; : &quot;HUGE!&quot; }
507
+ <p>Example:</p>
439
508
 
440
- json.key(:mistake) do
441
- json.key(:type, &quot;HUGE!&quot;)
442
- end
509
+ <p>json.key(:mistake, &quot;HUGE!&quot;)</p>
443
510
 
444
- { &quot;mistake&quot; : { &quot;type&quot; : &quot;HUGE!&quot; } }
511
+ <p>{ &quot;mistake&quot; : &quot;HUGE!&quot; }</p>
445
512
 
446
- json.key(:mistake) do
447
- json.add(&quot;HUGE!&quot;)
448
- end
513
+ <p>json.key(:mistake) do
514
+ json.key(:type, &quot;HUGE!&quot;)
515
+ end</p>
449
516
 
450
- { &quot;mistake&quot; : [ &quot;HUGE!&quot; ] }</code></pre>
517
+ <p>{ &quot;mistake&quot; : { &quot;type&quot; : &quot;HUGE!&quot; } }</p>
518
+
519
+ <p>json.key(:mistake) do
520
+ json.add(&quot;HUGE!&quot;)
521
+ end</p>
522
+
523
+ <p>{ &quot;mistake&quot; : [ &quot;HUGE!&quot; ] }</p>
451
524
 
452
525
 
453
526
  </div>
@@ -461,7 +534,6 @@ Example:
461
534
  <pre class="lines">
462
535
 
463
536
 
464
- 45
465
537
  46
466
538
  47
467
539
  48
@@ -481,12 +553,21 @@ Example:
481
553
  62
482
554
  63
483
555
  64
484
- 65</pre>
556
+ 65
557
+ 66
558
+ 67
559
+ 68
560
+ 69
561
+ 70</pre>
485
562
  </td>
486
563
  <td>
487
- <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 45</span>
564
+ <pre class="code"><span class="info file"># File 'lib/elster/streamer.rb', line 46</span>
488
565
 
489
566
  <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>
567
+ <span class='kw'>if</span> <span class='ivar'>@current_type</span> <span class='op'>==</span> <span class='symbol'>:array</span>
568
+ <span class='id identifier rubyid_raise'>raise</span> <span class='const'>JsonContainerTypeError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Attempted to write an object `key` value inside a JSON array.</span><span class='tstring_end'>&quot;</span></span>
569
+ <span class='kw'>end</span>
570
+
490
571
  <span class='kw'>if</span> <span class='ivar'>@item_count</span> <span class='op'>&gt;</span> <span class='int'>0</span>
491
572
  <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
573
  <span class='kw'>else</span>
@@ -517,9 +598,9 @@ Example:
517
598
  </div>
518
599
 
519
600
  <div id="footer">
520
- Generated on Sun Aug 19 23:07:22 2012 by
601
+ Generated on Tue Aug 21 21:31:10 2012 by
521
602
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
522
- 0.8.2.1 (ruby-1.9.2).
603
+ 0.8.2.1 (ruby-1.9.3).
523
604
  </div>
524
605
 
525
606
  </body>
@@ -93,6 +93,21 @@
93
93
  </ul>
94
94
 
95
95
 
96
+ <ul id="alpha_J" class="alpha">
97
+ <li class="letter">J</li>
98
+ <ul>
99
+
100
+ <li>
101
+ <span class='object_link'><a href="Elster/JsonContainerTypeError.html" title="Elster::JsonContainerTypeError (class)">JsonContainerTypeError</a></span>
102
+
103
+ <small>(Elster)</small>
104
+
105
+ </li>
106
+
107
+ </ul>
108
+ </ul>
109
+
110
+
96
111
  <ul id="alpha_S" class="alpha">
97
112
  <li class="letter">S</li>
98
113
  <ul>
@@ -116,9 +131,9 @@
116
131
  </div>
117
132
 
118
133
  <div id="footer">
119
- Generated on Sun Aug 19 23:07:22 2012 by
134
+ Generated on Tue Aug 21 21:31:10 2012 by
120
135
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
121
- 0.8.2.1 (ruby-1.9.2).
136
+ 0.8.2.1 (ruby-1.9.3).
122
137
  </div>
123
138
 
124
139
  </body>
@@ -45,7 +45,7 @@
45
45
 
46
46
  <ul id="full_list" class="class">
47
47
  <li><span class='object_link'><a href="top-level-namespace.html" title=" (root)">Top Level Namespace</a></span></li>
48
- <li><a class='toggle'></a> <span class='object_link'><a href="Elster.html" title="Elster (module)">Elster</a></span><small class='search_info'>Top Level Namespace</small></li><ul><li><span class='object_link'><a href="Elster/Streamer.html" title="Elster::Streamer (class)">Streamer</a></span> &lt; Object<small class='search_info'>Elster</small></li></ul>
48
+ <li><a class='toggle'></a> <span class='object_link'><a href="Elster.html" title="Elster (module)">Elster</a></span><small class='search_info'>Top Level Namespace</small></li><ul><li><span class='object_link'><a href="Elster/JsonContainerTypeError.html" title="Elster::JsonContainerTypeError (class)">JsonContainerTypeError</a></span> &lt; StandardError<small class='search_info'>Elster</small></li><li><span class='object_link'><a href="Elster/Streamer.html" title="Elster::Streamer (class)">Streamer</a></span> &lt; Object<small class='search_info'>Elster</small></li></ul>
49
49
 
50
50
  </ul>
51
51
  </div>
@@ -63,11 +63,11 @@
63
63
 
64
64
  <div id="content"><div id='filecontents'><h1>Elster</h1>
65
65
 
66
- <p>A simple streaming JSON encoder.</p>
66
+ <p>Elster is a streaming JSON encoder written in pure ruby.</p>
67
67
 
68
68
  <h2>Installation</h2>
69
69
 
70
- <p>Add this line to your application's Gemfile:</p>
70
+ <p>Add this line to your application&#39;s Gemfile:</p>
71
71
 
72
72
  <pre class="code ruby"><code><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>elster</span><span class='tstring_end'>'</span></span>
73
73
  </code></pre>
@@ -84,23 +84,34 @@
84
84
 
85
85
  <h2>Usage</h2>
86
86
 
87
- <p>TODO: Write usage instructions here</p>
87
+ <pre class="code ruby"><code><span class='id identifier rubyid_output'>output</span> <span class='op'>=</span> <span class='const'>StringIO</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
88
+ <span class='id identifier rubyid_json'>json</span> <span class='op'>=</span> <span class='const'>Elster</span><span class='op'>::</span><span class='const'>Streamer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_output'>output</span><span class='rparen'>)</span>
89
+ <span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>George</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
90
+ <span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='lparen'>(</span><span class='symbol'>:kids</span><span class='rparen'>)</span> <span class='kw'>do</span>
91
+ <span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Job</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
92
+ <span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Buster</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
93
+ <span class='kw'>end</span>
94
+ <span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
95
+
96
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_output'>output</span><span class='period'>.</span><span class='id identifier rubyid_string'>string</span>
97
+ <span class='comment'># {&quot;name&quot;:&quot;George&quot;,&quot;kids&quot;:[&quot;Job&quot;,&quot;Buster&quot;]}
98
+ </span></code></pre>
88
99
 
89
100
  <h2>Contributing</h2>
90
101
 
91
102
  <ol>
92
103
  <li>Fork it</li>
93
104
  <li>Create your feature branch (<code>git checkout -b my-new-feature</code>)</li>
94
- <li>Commit your changes (<code>git commit -am 'Added some feature'</code>)</li>
105
+ <li>Commit your changes (<code>git commit -am &#39;Added some feature&#39;</code>)</li>
95
106
  <li>Push to the branch (<code>git push origin my-new-feature</code>)</li>
96
107
  <li>Create new Pull Request</li>
97
108
  </ol>
98
109
  </div></div>
99
110
 
100
111
  <div id="footer">
101
- Generated on Sun Aug 19 23:07:22 2012 by
112
+ Generated on Tue Aug 21 21:31:10 2012 by
102
113
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
103
- 0.8.2.1 (ruby-1.9.2).
114
+ 0.8.2.1 (ruby-1.9.3).
104
115
  </div>
105
116
 
106
117
  </body>
@@ -63,11 +63,11 @@
63
63
 
64
64
  <div id="content"><div id='filecontents'><h1>Elster</h1>
65
65
 
66
- <p>A simple streaming JSON encoder.</p>
66
+ <p>Elster is a streaming JSON encoder written in pure ruby.</p>
67
67
 
68
68
  <h2>Installation</h2>
69
69
 
70
- <p>Add this line to your application's Gemfile:</p>
70
+ <p>Add this line to your application&#39;s Gemfile:</p>
71
71
 
72
72
  <pre class="code ruby"><code><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>elster</span><span class='tstring_end'>'</span></span>
73
73
  </code></pre>
@@ -84,23 +84,34 @@
84
84
 
85
85
  <h2>Usage</h2>
86
86
 
87
- <p>TODO: Write usage instructions here</p>
87
+ <pre class="code ruby"><code><span class='id identifier rubyid_output'>output</span> <span class='op'>=</span> <span class='const'>StringIO</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
88
+ <span class='id identifier rubyid_json'>json</span> <span class='op'>=</span> <span class='const'>Elster</span><span class='op'>::</span><span class='const'>Streamer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_output'>output</span><span class='rparen'>)</span>
89
+ <span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>George</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
90
+ <span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='lparen'>(</span><span class='symbol'>:kids</span><span class='rparen'>)</span> <span class='kw'>do</span>
91
+ <span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Job</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
92
+ <span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Buster</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
93
+ <span class='kw'>end</span>
94
+ <span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
95
+
96
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_output'>output</span><span class='period'>.</span><span class='id identifier rubyid_string'>string</span>
97
+ <span class='comment'># {&quot;name&quot;:&quot;George&quot;,&quot;kids&quot;:[&quot;Job&quot;,&quot;Buster&quot;]}
98
+ </span></code></pre>
88
99
 
89
100
  <h2>Contributing</h2>
90
101
 
91
102
  <ol>
92
103
  <li>Fork it</li>
93
104
  <li>Create your feature branch (<code>git checkout -b my-new-feature</code>)</li>
94
- <li>Commit your changes (<code>git commit -am 'Added some feature'</code>)</li>
105
+ <li>Commit your changes (<code>git commit -am &#39;Added some feature&#39;</code>)</li>
95
106
  <li>Push to the branch (<code>git push origin my-new-feature</code>)</li>
96
107
  <li>Create new Pull Request</li>
97
108
  </ol>
98
109
  </div></div>
99
110
 
100
111
  <div id="footer">
101
- Generated on Sun Aug 19 23:07:22 2012 by
112
+ Generated on Tue Aug 21 21:31:10 2012 by
102
113
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
103
- 0.8.2.1 (ruby-1.9.2).
114
+ 0.8.2.1 (ruby-1.9.3).
104
115
  </div>
105
116
 
106
117
  </body>
@@ -78,6 +78,14 @@
78
78
  </li>
79
79
 
80
80
 
81
+ <li class="r1 ">
82
+ <span class='object_link'><a href="Elster/Streamer.html#output-instance_method" title="Elster::Streamer#output (method)">#output</a></span>
83
+
84
+ <small>Elster::Streamer</small>
85
+
86
+ </li>
87
+
88
+
81
89
  </ul>
82
90
  </div>
83
91
  </body>
@@ -103,9 +103,9 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Sun Aug 19 23:07:22 2012 by
106
+ Generated on Tue Aug 21 21:31:10 2012 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
- 0.8.2.1 (ruby-1.9.2).
108
+ 0.8.2.1 (ruby-1.9.3).
109
109
  </div>
110
110
 
111
111
  </body>
@@ -26,21 +26,21 @@ module Elster
26
26
  #
27
27
  # Example:
28
28
  #
29
- # json.key(:mistake, "HUGE!")
29
+ # json.key(:mistake, "HUGE!")
30
30
  #
31
- # { "mistake" : "HUGE!" }
31
+ # { "mistake" : "HUGE!" }
32
32
  #
33
33
  #
34
- # json.key(:mistake) do
35
- # json.key(:type, "HUGE!")
36
- # end
34
+ # json.key(:mistake) do
35
+ # json.key(:type, "HUGE!")
36
+ # end
37
37
  #
38
- # { "mistake" : { "type" : "HUGE!" } }
38
+ # { "mistake" : { "type" : "HUGE!" } }
39
39
  #
40
40
  #
41
- # json.key(:mistake) do
42
- # json.add("HUGE!")
43
- # end
41
+ # json.key(:mistake) do
42
+ # json.add("HUGE!")
43
+ # end
44
44
  #
45
45
  # { "mistake" : [ "HUGE!" ] }
46
46
  def key(key, value=nil, &block)
@@ -59,14 +59,11 @@ module Elster
59
59
  write ":"
60
60
 
61
61
  if block
62
- nest_in
63
- block.call
64
- nest_out
62
+ call_block(block)
65
63
  else
66
64
  write encode_value(value)
65
+ @item_count += 1
67
66
  end
68
-
69
- @item_count += 1
70
67
  end
71
68
 
72
69
  # Output an array. If a block is passes the `value` will be ignored and a nested value
@@ -98,14 +95,11 @@ module Elster
98
95
  end
99
96
 
100
97
  if block
101
- nest_in
102
- block.call
103
- nest_out
98
+ call_block(block)
104
99
  else
105
100
  write encode_value(value)
101
+ @item_count += 1
106
102
  end
107
-
108
- @item_count += 1
109
103
  end
110
104
 
111
105
  protected
@@ -188,5 +182,22 @@ module Elster
188
182
  write("}")
189
183
  end
190
184
  end
185
+
186
+ def call_block(block)
187
+ nest_in
188
+ begin
189
+ block.call
190
+ rescue
191
+ raise
192
+ ensure
193
+ if @item_count == 0
194
+ write encode_value(nil)
195
+ @item_count += 1
196
+ else
197
+ nest_out
198
+ @item_count += 1
199
+ end
200
+ end
201
+ end
191
202
  end
192
203
  end
@@ -1,3 +1,3 @@
1
1
  module Elster
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -205,4 +205,49 @@ class StreamerTest < MiniTest::Unit::TestCase
205
205
  json.add(1)
206
206
  end
207
207
  end
208
+
209
+ def test_valid_when_block_exception
210
+ begin
211
+ json.key "person" do
212
+ json.add "A value"
213
+ raise "An error"
214
+ end
215
+ rescue
216
+ # Nothing to do
217
+ end
218
+ json.key "people", 11
219
+ json.close
220
+
221
+ assert_equal 11, parsed["people"]
222
+ end
223
+
224
+ def test_valid_when_block_writes_nothing
225
+ json.key :empty do
226
+ end
227
+ json.close
228
+
229
+ assert_equal nil, parsed.fetch("empty")
230
+ end
231
+
232
+ def test_valid_when_block_writes_nothing_multiple_values
233
+ json.key :empty do
234
+ end
235
+ json.key :value, 1
236
+ json.close
237
+
238
+ assert_equal nil, parsed.fetch("empty")
239
+ assert_equal 1, parsed.fetch("value")
240
+ end
241
+
242
+ def test_valid_when_block_writes_nothing_multi_values_before_and_after
243
+ json.key :first_value, false
244
+ json.key :empty do
245
+ end
246
+ json.key :value, 1
247
+ json.close
248
+
249
+ assert_equal nil, parsed.fetch("empty")
250
+ assert_equal 1, parsed.fetch("value")
251
+ assert_equal false, parsed["first_value"]
252
+ end
208
253
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-21 00:00:00.000000000 Z
12
+ date: 2012-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -87,6 +87,7 @@ files:
87
87
  - /Users/jwebb/src/bigjason/elster/doc/css/common.css
88
88
  - /Users/jwebb/src/bigjason/elster/doc/css/full_list.css
89
89
  - /Users/jwebb/src/bigjason/elster/doc/css/style.css
90
+ - /Users/jwebb/src/bigjason/elster/doc/Elster/JsonContainerTypeError.html
90
91
  - /Users/jwebb/src/bigjason/elster/doc/Elster/Streamer.html
91
92
  - /Users/jwebb/src/bigjason/elster/doc/Elster.html
92
93
  - /Users/jwebb/src/bigjason/elster/doc/file.README.html
@@ -110,6 +111,7 @@ files:
110
111
  - /Users/jwebb/src/bigjason/elster/pkg/elster-0.0.3.gem
111
112
  - /Users/jwebb/src/bigjason/elster/pkg/elster-0.0.5.gem
112
113
  - /Users/jwebb/src/bigjason/elster/pkg/elster-0.0.6.gem
114
+ - /Users/jwebb/src/bigjason/elster/pkg/elster-0.0.7.gem
113
115
  - /Users/jwebb/src/bigjason/elster/Rakefile
114
116
  - /Users/jwebb/src/bigjason/elster/README.md
115
117
  - /Users/jwebb/src/bigjason/elster/test/streamer_test.rb
@@ -127,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
129
  version: '0'
128
130
  segments:
129
131
  - 0
130
- hash: -398928207981350799
132
+ hash: -2517217796330769857
131
133
  required_rubygems_version: !ruby/object:Gem::Requirement
132
134
  none: false
133
135
  requirements:
@@ -136,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
138
  version: '0'
137
139
  segments:
138
140
  - 0
139
- hash: -398928207981350799
141
+ hash: -2517217796330769857
140
142
  requirements: []
141
143
  rubyforge_project:
142
144
  rubygems_version: 1.8.24