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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: baa06ccdc85e122396611df9322e6d8343997cfe
4
- data.tar.gz: 27682e70af99b13fa8d8533865bf4aa37f1fe0d8
3
+ metadata.gz: 5ee86971f89e9cafa7efe36f529ae414c306ee29
4
+ data.tar.gz: 6f181f2a67f317358b2539bce2a9afcba305704a
5
5
  SHA512:
6
- metadata.gz: 131c75bb3ab428521cb9185e4f6ffb209d5a6385185f043fb145362233c7a5d19419054323de4c7536d4af499c299b94a310d017890a2fd9228ebb648fbb8ab6
7
- data.tar.gz: b4c58f19084da6b9cb02749adc6356eb14ef9a946ac9a4edfcf79330daa6e17898c7d10cc83d5b16d3fc4680fcc40b96adbee02325fee68e7307f863495319d3
6
+ metadata.gz: dc58bf1054526a12c767915ef3a2f51fa97f24fc91623c5d72eee01d1d8dc7d4925d014192cff5869ee40eb9eeed4e088b645c25bf0d1673b488b83676244b90
7
+ data.tar.gz: 9003354230697f6b3a902810b859d5fcbd5ed7a938d6651c44f0a3623c8401ff82f03fbaab8ed1a64ea47545fbe4c62390afe267cb422fadac40a588d607ee3a
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  group :development, :test do
6
- gem 'pry'
6
+ gem 'pry', '~> 0.9.0'
7
7
  gem 'pry-nav'
8
8
  gem 'rake'
9
9
  end
@@ -5,3 +5,7 @@
5
5
  == 1.0.1
6
6
 
7
7
  * Support custom encodings (UTF-8, UTF-16, etc).
8
+
9
+ == 1.0.2
10
+
11
+ * Add flush methods
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  json-write-stream
2
2
  =================
3
3
 
4
+ [![Build Status](https://travis-ci.org/camertron/json-write-stream.svg?branch=master)](http://travis-ci.org/camertron/json-write-stream)
5
+
4
6
  An easy, streaming way to generate JSON.
5
7
 
6
8
  ## Installation
@@ -62,7 +62,7 @@ class JsonWriteStream
62
62
  end
63
63
  end
64
64
 
65
- def close
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
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  class JsonWriteStream
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
@@ -33,6 +33,9 @@ class JsonWriteStream
33
33
  writer.close
34
34
  end
35
35
 
36
+ def flush
37
+ end
38
+
36
39
  def close
37
40
  stream.close
38
41
  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
@@ -17,6 +17,7 @@ class RoundtripChecker
17
17
  stream = StringIO.new
18
18
  writer = create_writer(stream)
19
19
  serialize(obj, writer)
20
+ writer.close
20
21
  new_obj = JSON.parse(stream.string)
21
22
  compare(obj, new_obj)
22
23
  end
@@ -3,13 +3,22 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe JsonWriteStream::YieldingWriter do
6
- let(:stream) { StringIO.new }
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
@@ -3,13 +3,22 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe JsonWriteStream::YieldingWriter do
6
- let(:stream) { StringIO.new }
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.1
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-08-20 00:00:00.000000000 Z
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.2.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.