abroad 4.1.1 → 4.1.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: 0b68ea68c52475a6416744f8605aacf49a680b44
4
- data.tar.gz: 9f3b19ef80343e6b157ccf016f8ee040ce422a0a
3
+ metadata.gz: b46d62e7ba153afa73884e35c5bc6f1ecaa7a8e3
4
+ data.tar.gz: 2b40cc7ffbff3270a2e20e66851a253e7b3fead4
5
5
  SHA512:
6
- metadata.gz: 9b4bb6fcdbb232870d7f88d654a010f0569b6490f8c00922adcc243c0e8a0ad1a78d924c75430267bd1e6ba292669def38e4c828bb385d008e2db3f09b4e3516
7
- data.tar.gz: 43ca2d4a935b470fe1de2e05d7aa74fb82898f73eeeec6d111dee6f882243690d8d76dd77c615eb9f15ec806d9bd5a1a4bb94c3c9b0fbd928c002f45b1d82e0a
6
+ metadata.gz: 89b758b0a1bb58e8a0242e1f9f8ce5213981ba338bdd7255e4fe6f7b9afb2c9a2138f35de3da6b291b7c9e90ee0168af42979571072e4662a9a6ed0b32e7b358
7
+ data.tar.gz: 7708f3064b712244753192b8dfa2e19f11b7c05270e0e51c3b0c68825b4f76bd276e91a1a52716aafa482d1ac9d78ebaa2656e1b2bbed59ff471467aa2619714
@@ -16,7 +16,7 @@ module Abroad
16
16
 
17
17
  def write_key_value(key, value)
18
18
  key_parts = split_key(key)
19
- trie.add(key_parts, encode(value))
19
+ add_key_value(key_parts, value)
20
20
  end
21
21
 
22
22
  def flush
@@ -28,6 +28,23 @@ module Abroad
28
28
 
29
29
  private
30
30
 
31
+ def add_key_value(key_parts, value)
32
+ case value
33
+ when Array
34
+ value.each_with_index do |element, idx|
35
+ add_key_value(key_parts + [idx.to_s], element)
36
+ end
37
+
38
+ when Hash
39
+ value.each_pair do |key, val|
40
+ add_key_value(key_parts + [key], val)
41
+ end
42
+
43
+ else
44
+ trie.add(key_parts, encode(value))
45
+ end
46
+ end
47
+
31
48
  def encode(value)
32
49
  case value
33
50
  when Array
@@ -59,7 +76,6 @@ module Abroad
59
76
  end
60
77
  end
61
78
 
62
- # depth-first
63
79
  def write_node(node, parent_key)
64
80
  if node
65
81
  if node.has_children?
@@ -77,13 +93,12 @@ module Abroad
77
93
  end
78
94
 
79
95
  def write_value(node, parent_key)
80
- value = (node ? node.value : '') || ''
96
+ value = coerce((node ? node.value : '') || '')
81
97
 
82
- case value
83
- when Array
84
- write_array_value(parent_key, value)
85
- else
86
- write_textual_value(parent_key, value)
98
+ if writer.in_map?
99
+ writer.write_key_value(parent_key, value)
100
+ else
101
+ writer.write_element(value)
87
102
  end
88
103
  end
89
104
 
@@ -99,27 +114,6 @@ module Abroad
99
114
  end
100
115
  end
101
116
 
102
- def write_textual_value(parent_key, value)
103
- value = coerce(value)
104
-
105
- if writer.in_map?
106
- writer.write_key_value(parent_key, value)
107
- else
108
- writer.write_element(value)
109
- end
110
- end
111
-
112
- def write_array_value(parent_key, elements)
113
- # we should _always_ be in a map, but just in case...
114
- writer.write_sequence(parent_key) if writer.in_map?
115
-
116
- elements.each do |element|
117
- writer.write_element(coerce(element))
118
- end
119
-
120
- writer.close_sequence
121
- end
122
-
123
117
  def write_map(node, parent_key)
124
118
  if writer.in_map?
125
119
  writer.write_map(parent_key)
@@ -158,8 +152,8 @@ module Abroad
158
152
  arr[idx] = node.children[idx.to_s]
159
153
  end
160
154
  end
161
- end
162
155
 
156
+ end
163
157
  end
164
158
  end
165
159
  end
@@ -1,3 +1,3 @@
1
1
  module Abroad
2
- VERSION = '4.1.1'
2
+ VERSION = '4.1.2'
3
3
  end
@@ -159,6 +159,24 @@ describe Abroad::Serializers::Yaml::RailsSerializer do
159
159
  })
160
160
  end
161
161
 
162
+ it 'works for nested arrays' do
163
+ result = serialize do
164
+ serializer.write_key_value('foo', [
165
+ { 'bar' => %w(a b), 'baz' => 'boo' },
166
+ { 'bar' => %w(c d), 'baz' => 'bop' }
167
+ ])
168
+ end
169
+
170
+ expect(result).to eq({
171
+ 'fr' => {
172
+ 'foo' => [
173
+ { 'bar' => %w(a b), 'baz' => 'boo' },
174
+ { 'bar' => %w(c d), 'baz' => 'bop' }
175
+ ]
176
+ }
177
+ })
178
+ end
179
+
162
180
  it 'writes nested key/value pairs and arrays (in any order)' do
163
181
  result = serialize do
164
182
  serializer.write_key_value('foo.0.bar.0', 'a')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abroad
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.1.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: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2016-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities