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.
- checksums.yaml +4 -4
- data/lib/outstream/json.rb +27 -14
- data/test/test_json.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 734d7b472aa611644f4da6540a3e99ab8fd0485a
|
4
|
+
data.tar.gz: 5c24eb6f91c9962b7573c049c3826d2c5598aa15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 734fffbc53a50f7f5de64eeb909d7473baa51e46883edbfb5106463ea2b24e1595e583544e9904fb03a374e194641572cc1ca82d96036f20673eea0add5f3f02
|
7
|
+
data.tar.gz: 6e30870b7ac6be1927f7a8db6d85cdf0405e5f48377b43a8d9c73df2b55fd597035a98773e728a4449c3f564a022467acbdf791f8dad51534cc199c512131717
|
data/lib/outstream/json.rb
CHANGED
@@ -99,21 +99,29 @@ module Outstream
|
|
99
99
|
@count[@count.size-1] += 1
|
100
100
|
end
|
101
101
|
def add_object
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
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.
|
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-
|
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.
|