yaml-write-stream 1.0.2 → 1.0.3

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: 107519550465c7b9032c5eb05c621385cc868a32
4
- data.tar.gz: 7ef14e1fb90206f91f808f4a5c65fbea9892b418
3
+ metadata.gz: 5763f8ecccf5b43ed37bb2ba5732a46565f25b37
4
+ data.tar.gz: db9ca82e64965b2139d835cc817dfe41d6ce0db3
5
5
  SHA512:
6
- metadata.gz: f4d9fbd1689b5f9671f646f5a603474f486c56eeb4678babfaf385b0ac832a7078046076c5770a9ed7b412444f6436cbbd73cb07bbcfe36c1f961c4c81e83b23
7
- data.tar.gz: f47f0602e05a89515713dc7fae16d6dfc4c9a58e37f7e416e842e407cca4e88ab87f30548a746015aef58ff6c239f470c701e44c1f1b10d90a092779bc00ab9b
6
+ metadata.gz: e834bb3a518dbae4fa396a70851f8412dcbaaf8dbb033a8c5915e02fadc4759017809305bcc0f36f1ded5df24cb06975fbab864cbd428021be5ba2ca57a1a010
7
+ data.tar.gz: 4b6cc1fa51d600039ba57437bd257915d5b17e34c3c6bc98a83c6a43770258abe88d9123492862fd8dce3a5f528a57f49c7588a1e4653b6c1fd1ab78b918e61a
@@ -9,3 +9,10 @@
9
9
  == 1.0.2
10
10
 
11
11
  * Flush the underlying stream too.
12
+
13
+ == 1.0.3
14
+
15
+ * Fixed treatment of nils and blank strings. Nils should be written as blank entries while
16
+ blank strings should be wrapped in quotes so YAML parsers know to return a blank string
17
+ instead of a nil. Eg. foo: should parse as {"foo":nil} while foo: "" should parse as
18
+ {"foo":""}.
@@ -115,9 +115,18 @@ class YamlWriteStream
115
115
  end
116
116
 
117
117
  def write_scalar(value)
118
- # value, anchor, tag, plain, quoted, style
118
+ style = if value == ''
119
+ Psych::Nodes::Scalar::DOUBLE_QUOTED
120
+ else
121
+ Psych::Nodes::Scalar::ANY
122
+ end
123
+
124
+ quoted = value == ''
125
+ value = value ? value : ''
126
+
127
+ # value, anchor, tag, plain, quoted, style
119
128
  emitter.scalar(
120
- value, nil, nil, true, false, Psych::Nodes::Scalar::ANY
129
+ value, nil, nil, true, quoted, style
121
130
  )
122
131
  end
123
132
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  class YamlWriteStream
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.3"
5
5
  end
@@ -54,9 +54,18 @@ class YamlWriteStream
54
54
  def write_scalar(value)
55
55
  @first = false
56
56
 
57
- # value, anchor, tag, plain, quoted, style
57
+ style = if value == ''
58
+ Psych::Nodes::Scalar::DOUBLE_QUOTED
59
+ else
60
+ Psych::Nodes::Scalar::ANY
61
+ end
62
+
63
+ quoted = value == ''
64
+ value = value ? value : ''
65
+
66
+ # value, anchor, tag, plain, quoted, style
58
67
  emitter.scalar(
59
- value, nil, nil, true, false, Psych::Nodes::Scalar::ANY
68
+ value, nil, nil, true, quoted, style
60
69
  )
61
70
  end
62
71
  end
@@ -35,6 +35,26 @@ describe YamlWriteStream::YieldingWriter do
35
35
  expect(stream_writer).to be_closed
36
36
  expect(stream).to be_closed
37
37
  end
38
+
39
+ it 'quotes empty strings' do
40
+ stream_writer.write_map
41
+ stream_writer.write_key_value('foo', '')
42
+ stream_writer.close
43
+
44
+ expect(stream.string).to eq(utf8("foo: \"\"\n"))
45
+ expect(stream_writer).to be_closed
46
+ expect(stream).to be_closed
47
+ end
48
+
49
+ it 'writes nils as blank entries' do
50
+ stream_writer.write_map
51
+ stream_writer.write_key_value('foo', nil)
52
+ stream_writer.close
53
+
54
+ expect(stream.string).to eq(utf8("foo: \n"))
55
+ expect(stream_writer).to be_closed
56
+ expect(stream).to be_closed
57
+ end
38
58
  end
39
59
 
40
60
  describe '#closed?' do
@@ -28,5 +28,23 @@ describe YamlWriteStream::YieldingWriter do
28
28
  stream_writer.close
29
29
  expect(stream).to be_closed
30
30
  end
31
+
32
+ it 'quotes empty strings' do
33
+ stream_writer.write_map do |map_writer|
34
+ map_writer.write_key_value('foo', '')
35
+ end
36
+
37
+ stream_writer.close
38
+ expect(stream.string).to eq("foo: \"\"\n")
39
+ end
40
+
41
+ it 'writes nils as blank entries' do
42
+ stream_writer.write_map do |map_writer|
43
+ map_writer.write_key_value('foo', nil)
44
+ end
45
+
46
+ stream_writer.close
47
+ expect(stream.string).to eq("foo: \n")
48
+ end
31
49
  end
32
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml-write-stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-13 00:00:00.000000000 Z
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An easy, streaming way to generate YAML.
14
14
  email:
@@ -17,10 +17,10 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - lib/yaml-write-stream.rb
20
21
  - lib/yaml-write-stream/stateful.rb
21
22
  - lib/yaml-write-stream/version.rb
22
23
  - lib/yaml-write-stream/yielding.rb
23
- - lib/yaml-write-stream.rb
24
24
  - spec/shared_examples.rb
25
25
  - spec/spec_helper.rb
26
26
  - spec/stateful_spec.rb
@@ -34,7 +34,7 @@ files:
34
34
  homepage: http://github.com/camertron
35
35
  licenses: []
36
36
  metadata: {}
37
- post_install_message:
37
+ post_install_message:
38
38
  rdoc_options: []
39
39
  require_paths:
40
40
  - lib
@@ -49,9 +49,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
- rubyforge_project:
53
- rubygems_version: 2.0.14
54
- signing_key:
52
+ rubyforge_project:
53
+ rubygems_version: 2.1.9
54
+ signing_key:
55
55
  specification_version: 4
56
56
  summary: An easy, streaming way to generate YAML.
57
57
  test_files: []
58
+ has_rdoc: true