i18n_flow 0.2.2 → 0.2.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: 157be720fa6ecf3e7525a75e8ce298e60287e65c
4
- data.tar.gz: f21d1957ec6bcfe491df0768e2205f30cffef921
3
+ metadata.gz: e702abf0558b8dd1ebdd15e1f7823d677b649d6a
4
+ data.tar.gz: 99d568369b4ed3cd399147147174df3588ffcadd
5
5
  SHA512:
6
- metadata.gz: 262fd31678a1aefa44651f0a5210431988d265857939ecf56b2fd69e7cb944f496f470d6a32533fa960658deedf0a259a46a580e6fb20b708410e2b602da5c3d
7
- data.tar.gz: a8802ced6c6dcb06136c967bf5c074da02e4b4c9571eafb3850e940c67b5fb0e2892a47f64b7630827390e81674ac0f96933926d015d127f711b579e70463b25
6
+ metadata.gz: a786734b4ae407a51ab284cef2f610aa237ce49c3f8e8ff8ae7717b278954e82ebc448d7773b5f51fba7f98cc84816c174a7069ccacf46105a3377d3524948aa
7
+ data.tar.gz: b1798e0ff0fb80750521f5decbe8db769371518192edb0831b7b627c87831661897d22db36db273b91ac40a6d7a03f44c5821c29b5a7fdcd2a3887b07ee598aa
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i18n_flow (0.2.2)
4
+ i18n_flow (0.2.3)
5
5
  psych (>= 3.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  module I18nFlow
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- REVISION = 2
4
+ REVISION = 3
5
5
 
6
6
  VERSION = [MAJOR, MINOR, REVISION].join('.')
7
7
  end
@@ -90,4 +90,8 @@ private
90
90
  .tap { |n| break unless n.is_a?(Psych::Nodes::Mapping) }
91
91
  &.tap { |n| break n.children[layout_offset] }
92
92
  end
93
+
94
+ def self.scalar_scanner
95
+ @scalar_scanner ||= Psych::ScalarScanner.new(Psych::ClassLoader.new)
96
+ end
93
97
  end
@@ -79,7 +79,7 @@ module I18nFlow::YamlAstProxy
79
79
  def synchronize!
80
80
  return if @locked
81
81
 
82
- children = indexed_object.flat_map { |k, v| [Psych::Nodes::Scalar.new(k), v] }
82
+ children = indexed_object.flat_map { |k, v| [key_node(k), v] }
83
83
  node.children.replace(children)
84
84
  end
85
85
 
@@ -95,5 +95,14 @@ module I18nFlow::YamlAstProxy
95
95
  else node.anchor ? -2 : 0
96
96
  end
97
97
  end
98
+
99
+ def key_node(str)
100
+ needs_quote = !I18nFlow::YamlAstProxy.scalar_scanner.tokenize(str).is_a?(String)
101
+ if needs_quote
102
+ Psych::Nodes::Scalar.new(str, nil, nil, true, true, Psych::Nodes::Scalar::DOUBLE_QUOTED)
103
+ else
104
+ Psych::Nodes::Scalar.new(str, nil, nil, true, false, Psych::Nodes::Scalar::PLAIN)
105
+ end
106
+ end
98
107
  end
99
108
  end
@@ -8,6 +8,28 @@ describe I18nFlow::Formatter do
8
8
  end
9
9
 
10
10
  describe '#format!' do
11
+ it 'should quote non-string keys' do
12
+ ast = parse_yaml(<<-YAML)
13
+ en:
14
+ 1: alpha
15
+ 1.2: bravo
16
+ foo: chalie
17
+ true: delta
18
+ YAML
19
+ result = parse_yaml(<<-YAML)
20
+ en:
21
+ "1": alpha
22
+ "1.2": bravo
23
+ foo: chalie
24
+ "true": delta
25
+ YAML
26
+
27
+ p ast
28
+
29
+ formatted = format_ast(ast)
30
+ expect(formatted.to_yaml).to eq(result.to_yaml)
31
+ end
32
+
11
33
  it 'should remove extra whitespaces' do
12
34
  ast = parse_yaml(<<-YAML)
13
35
  en:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Iwanaga