abroad 3.0.1 → 4.0.0

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: 4cbe6a333acda4b792403b71bed3161dd123ee5d
4
- data.tar.gz: 20790811f1e0927b0a0b2962f8f433f6e6b7ec7e
3
+ metadata.gz: fcb32afa30cfd263c2443b4971a543a30a37e982
4
+ data.tar.gz: 2ba239c1134ab0a8d5b096733d7f0776eb1abe7b
5
5
  SHA512:
6
- metadata.gz: 2bb927936eff4941f64c053da29d1aca9452b58ba1ac92f0844da29390383c22b7be982ae678ec2c462e346d538fa29b04b2cecd5202ffe8caec7ab37aa47b85
7
- data.tar.gz: c23e65ec8f4783daf0e3609aad162996c2e241bf6316bbdb30525d4a62f45c5acb5d76ff380fc85de0f76e7ec632be750c9022a0396846dc7bc7ab655dbb74d4
6
+ metadata.gz: ad1be8571ab5b171ee69d3ab85e4dc5ccab5bf2f276e79fdf1bfc47deb223b2c41b32edeee6c39ba2c912bf60a80e69031d6fdbf47faefe97dd2fada714d3732
7
+ data.tar.gz: c78e0ad8cd0561510b86fa4f9cb7d6ce42f47d29aec7434390c6d72ca27a5f3af17a23b6855fad8704cc6522ba78eb96c772c260eb9733ed0f558c6c6260db67
@@ -17,7 +17,8 @@ module Abroad
17
17
  case obj
18
18
  when Hash
19
19
  obj.each_pair do |key, val|
20
- walk(val, cur_path + [key], &block)
20
+ segment = is_numeric?(key) ? "'#{key}'" : key
21
+ walk(val, cur_path + [segment], &block)
21
22
  end
22
23
  when Array
23
24
  obj.each_with_index do |val, idx|
@@ -28,11 +29,13 @@ module Abroad
28
29
  end
29
30
  end
30
31
 
31
- private
32
-
33
32
  def scrub_path(path)
34
33
  path # no-op
35
34
  end
35
+
36
+ def is_numeric?(str)
37
+ !!(str.to_s =~ /\d+/)
38
+ end
36
39
  end
37
40
 
38
41
  end
@@ -39,11 +39,19 @@ module Abroad
39
39
  key.split(/\.(?!\s)(?!\z)(?!\.)/)
40
40
  end
41
41
 
42
+ def unquote_numeric(str)
43
+ if match = str.match(/\A'(\d+)'\z/)
44
+ match.captures.first
45
+ else
46
+ str
47
+ end
48
+ end
49
+
42
50
  # depth-first
43
51
  def write_node(node, parent_key)
44
52
  if node
45
53
  if node.has_children?
46
- if children_are_sequence(node)
54
+ if children_are_sequence?(node)
47
55
  write_sequence(node, parent_key)
48
56
  else
49
57
  write_map(node, parent_key)
@@ -73,7 +81,7 @@ module Abroad
73
81
  end
74
82
 
75
83
  node.each_child do |key, child|
76
- write_node(child, key)
84
+ write_node(child, unquote_numeric(key))
77
85
  end
78
86
 
79
87
  writer.close_map
@@ -93,7 +101,7 @@ module Abroad
93
101
  writer.close_sequence
94
102
  end
95
103
 
96
- def children_are_sequence(node)
104
+ def children_are_sequence?(node)
97
105
  node.children.all? { |key, _| key =~ /\A[\d]+\z/ }
98
106
  end
99
107
 
@@ -1,3 +1,3 @@
1
1
  module Abroad
2
- VERSION = '3.0.1'
2
+ VERSION = '4.0.0'
3
3
  end
@@ -73,3 +73,10 @@
73
73
  string: A game room with video games, board games, foosball, ping-pong, and shuffleboard
74
74
  - key: en.jobs.benefits.4.body.2
75
75
  string: A Culture Team behind office happy hours and Hawai'i holiday parties
76
+ numeric_keys.yml:
77
+ - key: en.status_codes.'201'
78
+ string: Created
79
+ - key: en.status_codes.'304'
80
+ string: Redirect
81
+ - key: en.status_codes.'500'
82
+ string: Server error
@@ -0,0 +1,5 @@
1
+ en:
2
+ status_codes:
3
+ 201: Created
4
+ 304: Redirect
5
+ 500: Server error
@@ -169,6 +169,24 @@ describe Yaml::RailsSerializer do
169
169
  })
170
170
  end
171
171
 
172
+ it 'unquotes numeric keys' do
173
+ result = serialize do
174
+ serializer.write_key_value("status_codes.'201'", 'Created')
175
+ serializer.write_key_value("status_codes.'304'", 'Redirect')
176
+ serializer.write_key_value("status_codes.'500'", 'Server error')
177
+ end
178
+
179
+ expect(result).to eq({
180
+ 'fr' => {
181
+ 'status_codes' => {
182
+ 201 => 'Created',
183
+ 304 => 'Redirect',
184
+ 500 => 'Server error'
185
+ }
186
+ }
187
+ })
188
+ end
189
+
172
190
  it 'converts nils to empty strings' do
173
191
  result = serialize do
174
192
  serializer.write_key_value('foo.bar', nil)
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: 3.0.1
4
+ version: 4.0.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: 2016-06-14 00:00:00.000000000 Z
11
+ date: 2016-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -153,6 +153,7 @@ files:
153
153
  - spec/extractors/yaml/fixtures/invalid_single_quote_escape.yml
154
154
  - spec/extractors/yaml/fixtures/invalid_single_quote_escape_array.yml
155
155
  - spec/extractors/yaml/fixtures/nesting.yml
156
+ - spec/extractors/yaml/fixtures/numeric_keys.yml
156
157
  - spec/extractors/yaml/fixtures/short.yml
157
158
  - spec/extractors/yaml/jruby_compat_spec.rb
158
159
  - spec/extractors/yaml/yaml_extractor_spec.rb