json-write-stream 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +4 -0
- data/lib/json-write-stream.rb +1 -0
- data/lib/json-write-stream/stateful.rb +7 -5
- data/lib/json-write-stream/version.rb +1 -1
- data/lib/json-write-stream/yielding.rb +13 -9
- data/spec/stateful_spec.rb +16 -0
- data/spec/yielding_spec.rb +16 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7445d1cf85a82a9414433ebbdb06008eac6ac4e2
|
4
|
+
data.tar.gz: a82b04356133b8b46c21906bab7d413aebeac855
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3818ce8ae032e722dbde636aaefa818975e91ab25a80e20045da648564051dffde7c12fb9e9291c9ecb2ad0bad48c2438665b672f2f773549f60339f6f4b163a
|
7
|
+
data.tar.gz: 3632c1b6c3b499f20f46e3577f60221a15aec7a10e523a3d39b84b9d6513a9ff83deb6ee8bed07cc4d3dad5fedd7ef6f9b3a1cc255ce7a00f397ee2835cbc27a
|
data/History.txt
CHANGED
data/lib/json-write-stream.rb
CHANGED
@@ -139,12 +139,14 @@ class JsonWriteStream
|
|
139
139
|
stream.write(':')
|
140
140
|
end
|
141
141
|
|
142
|
-
def write_key_value(key, value,
|
142
|
+
def write_key_value(key, value, options = DEFAULT_OPTIONS)
|
143
143
|
write_comma
|
144
|
-
stream.write(before)
|
144
|
+
stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
|
145
145
|
increment
|
146
146
|
write_key(key)
|
147
|
-
stream.write(
|
147
|
+
stream.write(':')
|
148
|
+
stream.write(options.fetch(:between, DEFAULT_OPTIONS[:between]))
|
149
|
+
stream.write(escape(value))
|
148
150
|
end
|
149
151
|
|
150
152
|
def close
|
@@ -176,9 +178,9 @@ class JsonWriteStream
|
|
176
178
|
stream.write('[')
|
177
179
|
end
|
178
180
|
|
179
|
-
def write_element(element,
|
181
|
+
def write_element(element, options = DEFAULT_OPTIONS)
|
180
182
|
write_comma
|
181
|
-
stream.write(before)
|
183
|
+
stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
|
182
184
|
increment
|
183
185
|
stream.write(escape(element))
|
184
186
|
end
|
@@ -60,30 +60,34 @@ class JsonWriteStream
|
|
60
60
|
stream.write('{')
|
61
61
|
end
|
62
62
|
|
63
|
-
def write_array(key,
|
63
|
+
def write_array(key, options = DEFAULT_OPTIONS)
|
64
64
|
write_comma
|
65
|
-
stream.write(before)
|
65
|
+
stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
|
66
66
|
increment
|
67
67
|
write_key(key)
|
68
68
|
stream.write(':')
|
69
|
+
stream.write(options.fetch(:between, DEFAULT_OPTIONS[:between]))
|
69
70
|
super(true)
|
70
71
|
end
|
71
72
|
|
72
|
-
def write_object(key,
|
73
|
+
def write_object(key, options = DEFAULT_OPTIONS)
|
73
74
|
write_comma
|
74
|
-
stream.write(before)
|
75
|
+
stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
|
75
76
|
increment
|
76
77
|
write_key(key)
|
77
78
|
stream.write(':')
|
79
|
+
stream.write(options.fetch(:between, DEFAULT_OPTIONS[:between]))
|
78
80
|
super(true)
|
79
81
|
end
|
80
82
|
|
81
|
-
def write_key_value(key, value,
|
83
|
+
def write_key_value(key, value, options = DEFAULT_OPTIONS)
|
82
84
|
write_comma
|
83
|
-
stream.write(before)
|
85
|
+
stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
|
84
86
|
increment
|
85
87
|
write_key(key)
|
86
|
-
stream.write(
|
88
|
+
stream.write(':')
|
89
|
+
stream.write(options.fetch(:between, DEFAULT_OPTIONS[:between]))
|
90
|
+
stream.write(escape(value))
|
87
91
|
end
|
88
92
|
|
89
93
|
def close
|
@@ -102,9 +106,9 @@ class JsonWriteStream
|
|
102
106
|
stream.write('[')
|
103
107
|
end
|
104
108
|
|
105
|
-
def write_element(element,
|
109
|
+
def write_element(element, options = DEFAULT_OPTIONS)
|
106
110
|
write_comma
|
107
|
-
stream.write(before)
|
111
|
+
stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
|
108
112
|
increment
|
109
113
|
stream.write(escape(element))
|
110
114
|
end
|
data/spec/stateful_spec.rb
CHANGED
@@ -21,6 +21,22 @@ describe JsonWriteStream::YieldingWriter do
|
|
21
21
|
|
22
22
|
it_behaves_like 'a json stream'
|
23
23
|
|
24
|
+
it 'respects the "before" option' do
|
25
|
+
stream_writer.write_object
|
26
|
+
stream_writer.write_key_value('foo', 'bar', before: "\n ")
|
27
|
+
stream_writer.close
|
28
|
+
|
29
|
+
expect(stream.string).to eq("{\n \"foo\":\"bar\"}")
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'respects the "between" option' do
|
33
|
+
stream_writer.write_object
|
34
|
+
stream_writer.write_key_value('foo', 'bar', between: ' ')
|
35
|
+
stream_writer.close
|
36
|
+
|
37
|
+
expect(stream.string).to eq('{"foo": "bar"}')
|
38
|
+
end
|
39
|
+
|
24
40
|
describe '#close' do
|
25
41
|
it 'unwinds the stack, adds appropriate closing punctuation for each unclosed item, and closes the stream' do
|
26
42
|
stream_writer.write_array
|
data/spec/yielding_spec.rb
CHANGED
@@ -21,6 +21,22 @@ describe JsonWriteStream::YieldingWriter do
|
|
21
21
|
|
22
22
|
it_behaves_like 'a json stream'
|
23
23
|
|
24
|
+
it 'respects the "before" option' do
|
25
|
+
stream_writer.write_object do |object_writer|
|
26
|
+
object_writer.write_key_value('foo', 'bar', before: "\n ")
|
27
|
+
end
|
28
|
+
|
29
|
+
expect(stream.string).to eq("{\n \"foo\":\"bar\"}")
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'respects the "between" option' do
|
33
|
+
stream_writer.write_object do |object_writer|
|
34
|
+
object_writer.write_key_value('foo', 'bar', between: ' ')
|
35
|
+
end
|
36
|
+
|
37
|
+
expect(stream.string).to eq('{"foo": "bar"}')
|
38
|
+
end
|
39
|
+
|
24
40
|
describe '#write_key_value' do
|
25
41
|
it 'converts all keys to strings' do
|
26
42
|
stream_writer.write_object do |object_writer|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-write-stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_pure
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.2
|
67
|
+
rubygems_version: 2.5.2
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: An easy, streaming way to generate JSON.
|