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 +4 -4
- data/lib/abroad/extractors/yaml/dotted_key_extractor.rb +6 -3
- data/lib/abroad/serializers/yaml/rails_serializer.rb +11 -3
- data/lib/abroad/version.rb +1 -1
- data/spec/extractors/yaml/fixtures.yml +7 -0
- data/spec/extractors/yaml/fixtures/numeric_keys.yml +5 -0
- data/spec/serializers/yaml/rails_serializer_spec.rb +18 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcb32afa30cfd263c2443b4971a543a30a37e982
|
4
|
+
data.tar.gz: 2ba239c1134ab0a8d5b096733d7f0776eb1abe7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
|
data/lib/abroad/version.rb
CHANGED
@@ -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
|
@@ -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:
|
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-
|
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
|