outstream-json 0.1.2 → 0.2.0

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/outstream/json.rb +27 -14
  3. data/test/test_json.rb +19 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb23d15ac017bb74a60f4d8b5d939ca4ea6a5220
4
- data.tar.gz: 850a1a01ec27e3f663a106ffc420ed858bdeda03
3
+ metadata.gz: 734d7b472aa611644f4da6540a3e99ab8fd0485a
4
+ data.tar.gz: 5c24eb6f91c9962b7573c049c3826d2c5598aa15
5
5
  SHA512:
6
- metadata.gz: 2ef5dc77093aa2024ac51a95da3729e5d3acc74bdb88585e633e5aeb9cf1d64fc9dc7fc64308e89adb4b0fdfe0f79729eeda92520d0baa2b178f6f508f69ee59
7
- data.tar.gz: e482b9774860e128bc00aa10c397a5303013661378682cd837720ec7f52df1e82b4f2e342842a6b203323366ed012ded2b0d011da44de1f5570f45f4a229f600
6
+ metadata.gz: 734fffbc53a50f7f5de64eeb909d7473baa51e46883edbfb5106463ea2b24e1595e583544e9904fb03a374e194641572cc1ca82d96036f20673eea0add5f3f02
7
+ data.tar.gz: 6e30870b7ac6be1927f7a8db6d85cdf0405e5f48377b43a8d9c73df2b55fd597035a98773e728a4449c3f564a022467acbdf791f8dad51534cc199c512131717
@@ -99,21 +99,29 @@ module Outstream
99
99
  @count[@count.size-1] += 1
100
100
  end
101
101
  def add_object
102
- write "{"
103
- @count.push 0
104
- result = yield
105
- @count.pop
106
- write "}"
107
-
108
- result
102
+ begin
103
+ write "{"
104
+ @count.push 0
105
+ return yield
106
+ rescue
107
+ raise
108
+ ensure
109
+ @count.pop
110
+ write "}"
111
+ end
109
112
  end
110
113
  def add_array(a)
111
- write "["
112
- a.enum_for(:each).each_with_index {|v,i|
113
- write "," if i > 0
114
- add_value v
115
- }
116
- write "]"
114
+ begin
115
+ write "["
116
+ a.enum_for(:each).each_with_index {|v,i|
117
+ write "," if i > 0
118
+ add_value v
119
+ }
120
+ rescue
121
+ raise
122
+ ensure
123
+ write "]"
124
+ end
117
125
  end
118
126
  def add_value(value)
119
127
  if value.respond_to?:each_pair
@@ -121,7 +129,12 @@ module Outstream
121
129
  elsif value.respond_to?:each
122
130
  add_array value
123
131
  elsif value.respond_to?:call
124
- add_value value.call
132
+ begin
133
+ add_value value.call
134
+ rescue
135
+ add_value nil
136
+ raise
137
+ end
125
138
  else
126
139
  write value.to_json
127
140
  end
data/test/test_json.rb CHANGED
@@ -113,5 +113,24 @@ class TestJson < Test::Unit::TestCase
113
113
  }
114
114
  assert_equal '{"foo":{"bar":"wow"}}', out.to_s
115
115
  end
116
+
117
+ def testException
118
+ out = Outstream::Json.create {
119
+ add "foo" do
120
+ add "bar" => lambda { raise }
121
+ end
122
+ }
123
+ tokens = []
124
+ assert_raise { out.each {|str| tokens << str} }
125
+ assert_equal %w({ "foo" : { "bar" : null } }), tokens
126
+ end
127
+ def testExceptionInArray
128
+ out = Outstream::Json.create {
129
+ add "foo" => [lambda { raise }]
130
+ }
131
+ tokens = []
132
+ assert_raise { out.each {|str| tokens << str} }
133
+ assert_equal %w({ "foo" : [ null ] }), tokens
134
+ end
116
135
  end
117
136
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outstream-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Calhoun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-02-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A library which provides a means for writing a large number of object
14
14
  as json without building the entire set in memory first.