json-write-stream 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/History.txt +4 -0
- data/README.md +2 -0
- data/lib/json-write-stream/stateful.rb +7 -2
- data/lib/json-write-stream/version.rb +1 -1
- data/lib/json-write-stream/yielding.rb +3 -0
- data/spec/json-write-stream_spec.rb +4 -4
- data/spec/spec_helper.rb +1 -0
- data/spec/stateful_spec.rb +11 -2
- data/spec/yielding_spec.rb +12 -3
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ee86971f89e9cafa7efe36f529ae414c306ee29
|
4
|
+
data.tar.gz: 6f181f2a67f317358b2539bce2a9afcba305704a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc58bf1054526a12c767915ef3a2f51fa97f24fc91623c5d72eee01d1d8dc7d4925d014192cff5869ee40eb9eeed4e088b645c25bf0d1673b488b83676244b90
|
7
|
+
data.tar.gz: 9003354230697f6b3a902810b859d5fcbd5ed7a938d6651c44f0a3623c8401ff82f03fbaab8ed1a64ea47545fbe4c62390afe267cb422fadac40a588d607ee3a
|
data/Gemfile
CHANGED
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -62,7 +62,7 @@ class JsonWriteStream
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
65
|
+
def flush
|
66
66
|
until stack.empty?
|
67
67
|
if in_object?
|
68
68
|
close_object
|
@@ -71,11 +71,16 @@ class JsonWriteStream
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
stream.close
|
75
74
|
@closed = true
|
76
75
|
nil
|
77
76
|
end
|
78
77
|
|
78
|
+
def close
|
79
|
+
flush
|
80
|
+
stream.close
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
|
79
84
|
def in_object?
|
80
85
|
current ? current.is_object? : false
|
81
86
|
end
|
@@ -31,8 +31,8 @@ describe JsonWriteStream do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
expect(stream.string.bytes).to_not eq('{"foo":"bar"}'.bytes)
|
35
|
-
expect(stream.string.encode(Encoding::UTF_8).bytes).to eq('{"foo":"bar"}'.bytes)
|
34
|
+
expect(stream.string.bytes.to_a).to_not eq('{"foo":"bar"}'.bytes.to_a)
|
35
|
+
expect(stream.string.encode(Encoding::UTF_8).bytes.to_a).to eq('{"foo":"bar"}'.bytes.to_a)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -62,8 +62,8 @@ describe JsonWriteStream do
|
|
62
62
|
written = tempfile.read
|
63
63
|
written.force_encoding(Encoding::UTF_16BE)
|
64
64
|
|
65
|
-
expect(written.bytes).to_not eq('{"foo":"bar"}'.bytes)
|
66
|
-
expect(written.encode(Encoding::UTF_8).bytes).to eq('{"foo":"bar"}'.bytes)
|
65
|
+
expect(written.bytes.to_a).to_not eq('{"foo":"bar"}'.bytes.to_a)
|
66
|
+
expect(written.encode(Encoding::UTF_8).bytes.to_a).to eq('{"foo":"bar"}'.bytes.to_a)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/stateful_spec.rb
CHANGED
@@ -3,13 +3,22 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe JsonWriteStream::YieldingWriter do
|
6
|
-
let(:stream)
|
6
|
+
let(:stream) do
|
7
|
+
StringIO.new.tap do |io|
|
8
|
+
io.set_encoding(Encoding::UTF_8)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
7
12
|
let(:stream_writer) { JsonWriteStream::StatefulWriter.new(stream) }
|
8
13
|
|
9
14
|
def check_roundtrip(obj)
|
10
15
|
StatefulRoundtripChecker.check_roundtrip(obj)
|
11
16
|
end
|
12
17
|
|
18
|
+
def utf8(str)
|
19
|
+
str.encode(Encoding::UTF_8)
|
20
|
+
end
|
21
|
+
|
13
22
|
it_behaves_like 'a json stream'
|
14
23
|
|
15
24
|
describe '#close' do
|
@@ -20,7 +29,7 @@ describe JsonWriteStream::YieldingWriter do
|
|
20
29
|
stream_writer.write_key_value('def', 'ghi')
|
21
30
|
stream_writer.close
|
22
31
|
|
23
|
-
expect(stream.string).to eq('["abc",{"def":"ghi"}]')
|
32
|
+
expect(stream.string).to eq(utf8('["abc",{"def":"ghi"}]'))
|
24
33
|
expect(stream_writer).to be_closed
|
25
34
|
expect(stream).to be_closed
|
26
35
|
end
|
data/spec/yielding_spec.rb
CHANGED
@@ -3,13 +3,22 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe JsonWriteStream::YieldingWriter do
|
6
|
-
let(:stream)
|
6
|
+
let(:stream) do
|
7
|
+
StringIO.new.tap do |io|
|
8
|
+
io.set_encoding(Encoding::UTF_8)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
7
12
|
let(:stream_writer) { JsonWriteStream::YieldingWriter.new(stream) }
|
8
13
|
|
9
14
|
def check_roundtrip(obj)
|
10
15
|
YieldingRoundtripChecker.check_roundtrip(obj)
|
11
16
|
end
|
12
17
|
|
18
|
+
def utf8(str)
|
19
|
+
str.encode(Encoding::UTF_8)
|
20
|
+
end
|
21
|
+
|
13
22
|
it_behaves_like 'a json stream'
|
14
23
|
|
15
24
|
describe '#write_key_value' do
|
@@ -18,7 +27,7 @@ describe JsonWriteStream::YieldingWriter do
|
|
18
27
|
object_writer.write_key_value(123, 'abc')
|
19
28
|
end
|
20
29
|
|
21
|
-
expect(stream.string).to eq('{"123":"abc"}')
|
30
|
+
expect(stream.string).to eq(utf8('{"123":"abc"}'))
|
22
31
|
end
|
23
32
|
|
24
33
|
it 'supports non-string values' do
|
@@ -27,7 +36,7 @@ describe JsonWriteStream::YieldingWriter do
|
|
27
36
|
object_writer.write_key_value('def', true)
|
28
37
|
end
|
29
38
|
|
30
|
-
expect(stream.string).to eq('{"abc":123,"def":true}')
|
39
|
+
expect(stream.string).to eq(utf8('{"abc":123,"def":true}'))
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
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.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_pure
|
@@ -31,20 +31,20 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
- Gemfile
|
35
|
-
- History.txt
|
36
|
-
- README.md
|
37
|
-
- Rakefile
|
38
|
-
- json-write-stream.gemspec
|
39
|
-
- lib/json-write-stream.rb
|
40
34
|
- lib/json-write-stream/stateful.rb
|
41
35
|
- lib/json-write-stream/version.rb
|
42
36
|
- lib/json-write-stream/yielding.rb
|
37
|
+
- lib/json-write-stream.rb
|
43
38
|
- spec/json-write-stream_spec.rb
|
44
39
|
- spec/shared_examples.rb
|
45
40
|
- spec/spec_helper.rb
|
46
41
|
- spec/stateful_spec.rb
|
47
42
|
- spec/yielding_spec.rb
|
43
|
+
- Gemfile
|
44
|
+
- History.txt
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- json-write-stream.gemspec
|
48
48
|
homepage: http://github.com/camertron
|
49
49
|
licenses: []
|
50
50
|
metadata: {}
|
@@ -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.
|
67
|
+
rubygems_version: 2.0.14
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: An easy, streaming way to generate JSON.
|