toml-rb 0.3.12 → 0.3.13

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: 4c2b333939107da6034d5d7a07235570450bef82
4
- data.tar.gz: f33142272084db45e792b5f33fb18fcc750ab726
3
+ metadata.gz: 0db308aa87a4da538be12f2ce08fcfb5d84ef70c
4
+ data.tar.gz: b169b923de908e25c9d10647f97408b4a41e1bfd
5
5
  SHA512:
6
- metadata.gz: 0883e07437300579d35b573db37420ce824b67038e4c0bd4435e78a09ca228212f285c2020e209c58231e460d3cdfef9024899afaf0cc4a25c0c0e657a0fe111
7
- data.tar.gz: 6a78ff8893c5dcdf6bce627d1c60eee7670285ea68af5f59805ec46af5b6c220400808aa11e5e80e70038e484ff3b3d49a593f1e30cb24b3dcceaf3ceb67d175
6
+ metadata.gz: ce740f5eabf651cba25cc8f536f73e55ec94d40f7b8b233b654b2d44aaceff3e5db912cde59b9cae45b05edf8032f12f634f6b26d68940a3a5ac1cce58a5ea83
7
+ data.tar.gz: af784c37f85445e7659638de52363065df3e8665cfc15f092b1aa4613426633a74ff8e389ab85c5b7db3bbfb048ff1c28f0f3ce0f8dab48b7c7d1351bb882b9a
@@ -11,20 +11,13 @@ module TOML
11
11
  private
12
12
 
13
13
  def visit(hash, prefix, extra_brackets = false)
14
- if hash.empty? && !prefix.empty?
15
- print_prefix prefix, extra_brackets
16
- else
17
- simple_pairs, nested_pairs, table_array_pairs = sort_pairs hash
14
+ simple_pairs, nested_pairs, table_array_pairs = sort_pairs hash
18
15
 
19
- unless prefix.empty? || simple_pairs.empty?
20
- print_prefix prefix, extra_brackets
21
- end
22
-
23
- # First add simple pairs, under the prefix
24
- dump_simple_pairs simple_pairs
25
- dump_nested_pairs nested_pairs, prefix
26
- dump_table_array_pairs table_array_pairs, prefix
16
+ if prefix.any? && (simple_pairs.any? || hash.empty?)
17
+ print_prefix prefix, extra_brackets
27
18
  end
19
+
20
+ dump_pairs simple_pairs, nested_pairs, table_array_pairs, prefix
28
21
  end
29
22
 
30
23
  def sort_pairs(hash)
@@ -48,6 +41,13 @@ module TOML
48
41
  [simple_pairs, nested_pairs, table_array_pairs]
49
42
  end
50
43
 
44
+ def dump_pairs(simple, nested, table_array, prefix = [])
45
+ # First add simple pairs, under the prefix
46
+ dump_simple_pairs simple
47
+ dump_nested_pairs nested, prefix
48
+ dump_table_array_pairs table_array, prefix
49
+ end
50
+
51
51
  def dump_simple_pairs(simple_pairs)
52
52
  simple_pairs.each do |key, val|
53
53
  key = quote_key(key) unless bare_key? key
@@ -69,11 +69,10 @@ module TOML
69
69
  aux_prefix = prefix + [key]
70
70
 
71
71
  val.each do |child|
72
- if child.empty?
73
- print_prefix aux_prefix, true
74
- else
75
- visit child, aux_prefix, true
76
- end
72
+ print_prefix aux_prefix, true
73
+ args = sort_pairs(child) << aux_prefix
74
+
75
+ dump_pairs(*args)
77
76
  end
78
77
  end
79
78
  end
@@ -22,11 +22,11 @@ grammar TOML::Primitive
22
22
  end
23
23
 
24
24
  rule multiline_string
25
- ('"""' line_break* (text:~'"""'|'') '"""' space) <TOML::MultilineString>
25
+ ('"""' line_break* (text:~('"""' !'"')|'') '"""' space) <TOML::MultilineString>
26
26
  end
27
27
 
28
28
  rule multiline_literal
29
- ("'''" line_break* (text:~"'''"|'') "'''" space) <TOML::MultilineLiteral>
29
+ ("'''" line_break* (text:~("'''" !"'")|'') "'''" space) <TOML::MultilineLiteral>
30
30
  end
31
31
 
32
32
  ##
@@ -19,6 +19,9 @@ module TOML
19
19
  # Read about the Visitor pattern
20
20
  # http://en.wikipedia.org/wiki/Visitor_pattern
21
21
  def visit_table_array(table_array)
22
+ table_array_key = table_array.full_key
23
+ @visited_keys.reject! { |k| k.start_with? table_array_key }
24
+
22
25
  @current = table_array.navigate_keys @hash, @symbolize_keys
23
26
  end
24
27
 
@@ -34,6 +34,10 @@ module TOML
34
34
  def accept_visitor(parser)
35
35
  parser.visit_table_array self
36
36
  end
37
+
38
+ def full_key
39
+ @nested_keys.join('.')
40
+ end
37
41
  end
38
42
 
39
43
  # Used in document.citrus
@@ -76,4 +76,19 @@ class DumperTest < Minitest::Test
76
76
 
77
77
  assert_equal toml, dumped
78
78
  end
79
+
80
+ def test_dump_array_tables
81
+ hash = { fruit: [{ physical: { color: "red" } }, { physical: { color: "blue" } }] }
82
+ dumped = TOML.dump(hash)
83
+ toml = <<-EOS.gsub(/^ {6}/, '')
84
+ [[fruit]]
85
+ [fruit.physical]
86
+ color = "red"
87
+ [[fruit]]
88
+ [fruit.physical]
89
+ color = "blue"
90
+ EOS
91
+
92
+ assert_equal toml, dumped
93
+ end
79
94
  end
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'toml-rb'
3
- s.version = '0.3.12'
3
+ s.version = '0.3.13'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
  s.summary = 'TOML parser in ruby, for ruby.'
6
6
  s.description = 'A TOML parser using Citrus parsing library. '
7
7
  s.authors = ['Emiliano Mancuso', 'Lucas Tolchinsky']
8
8
  s.email = ['emiliano.mancuso@gmail.com', 'lucas.tolchinsky@gmail.com']
9
- s.homepage = 'http://github.com/eMancu/toml-rb'
9
+ s.homepage = 'http://github.com/emancu/toml-rb'
10
10
  s.license = 'MIT'
11
11
 
12
12
  s.files = Dir[
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toml-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12
4
+ version: 0.3.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emiliano Mancuso
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-10 00:00:00.000000000 Z
12
+ date: 2016-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: citrus
@@ -65,7 +65,7 @@ files:
65
65
  - test/toml_examples.rb
66
66
  - test/toml_test.rb
67
67
  - toml-rb.gemspec
68
- homepage: http://github.com/eMancu/toml-rb
68
+ homepage: http://github.com/emancu/toml-rb
69
69
  licenses:
70
70
  - MIT
71
71
  metadata: {}