toml-rb 0.2.0 → 0.2.1

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: 97909cd5d9ac3403acf5fba07cfb3177fb343458
4
- data.tar.gz: ee82bae7cb2a1ec814b269390899ccd47781dabd
3
+ metadata.gz: d550c310fb16cc57d0bd5f2b5ca269d300c79268
4
+ data.tar.gz: e5be2acd18c3ee096743c749c59ef893f1f96058
5
5
  SHA512:
6
- metadata.gz: ef153da7a2aa9623a2554825b1604f460dfad351bfee4ed4078f2a45b3902992d4ecc2fae2d32b39ed37ef29182d9c4948b389584264e4b499b6f3acad261fd9
7
- data.tar.gz: 2869e5f5d5b5c946940d3d38cda21440378ba4162cf73c4218aac9c2904630b95e9b075151db1f2fe6449209641f4d65470307b4ac1b4ded510a44e8c0905fdc
6
+ metadata.gz: 2d3c00589a249387ead32123e022bb1387a39f887e9f155111b94d6e782ab29d50ecf1b5e5d464b6cec811a05f76505f35abe1b65c9a831b2eae6bfcd60f8c80
7
+ data.tar.gz: 6ff8631b538415e1f7806298dbc216beb952d05b944b478bad5281a78b5b393afdaacee4e3c8782e068d9f39a5d4b23ed7e545a6a7fc78a6ab491085a9d489d2
@@ -11,6 +11,19 @@ module TOML
11
11
  private
12
12
 
13
13
  def visit(hash, prefix, extra_brackets = false)
14
+ simple_pairs, nested_pairs, table_array_pairs = sort_pairs hash
15
+
16
+ unless prefix.empty? || simple_pairs.empty?
17
+ print_prefix prefix, extra_brackets
18
+ end
19
+
20
+ # First add simple pairs, under the prefix
21
+ dump_simple_pairs simple_pairs
22
+ dump_nested_pairs nested_pairs, prefix
23
+ dump_table_array_pairs table_array_pairs, prefix
24
+ end
25
+
26
+ def sort_pairs(hash)
14
27
  nested_pairs = []
15
28
  simple_pairs = []
16
29
  table_array_pairs = []
@@ -28,22 +41,25 @@ module TOML
28
41
  end
29
42
  end
30
43
 
31
- unless prefix.empty? || simple_pairs.empty?
32
- print_prefix prefix, extra_brackets
33
- end
44
+ return simple_pairs, nested_pairs, table_array_pairs
45
+ end
34
46
 
35
- # First add simple pairs, under the prefix
47
+ def dump_simple_pairs(simple_pairs)
36
48
  simple_pairs.each do |key, val|
37
49
  key = quote_key(key) unless bare_key? key
38
50
  @toml_str << "#{key} = #{to_toml(val)}\n"
39
51
  end
52
+ end
40
53
 
54
+ def dump_nested_pairs(nested_pairs, prefix)
41
55
  nested_pairs.each do |key, val|
42
56
  key = quote_key(key) unless bare_key? key
43
57
 
44
58
  visit val, prefix + [key], false
45
59
  end
60
+ end
46
61
 
62
+ def dump_table_array_pairs(table_array_pairs, prefix)
47
63
  table_array_pairs.each do |key, val|
48
64
  key = quote_key(key) unless bare_key? key
49
65
  aux_prefix = prefix + [key]
@@ -5,14 +5,26 @@ module TOML
5
5
  end
6
6
 
7
7
  def navigate_keys(hash, symbolize_keys = false)
8
+ last_key = @nested_keys.pop
9
+
10
+ # Go over the parent keys
8
11
  @nested_keys.each do |key|
9
12
  key = symbolize_keys ? key.to_sym : key
10
- hash[key] = [] unless hash[key]
11
- hash[key] << {} if @nested_keys.last == key.to_s || hash[key].empty?
12
- hash = hash[key].last
13
+ hash[key] = {} unless hash[key]
14
+
15
+ if hash[key].is_a? Array
16
+ hash[key] << {} if hash[key].empty?
17
+ hash = hash[key].last
18
+ else
19
+ hash = hash[key]
20
+ end
13
21
  end
14
22
 
15
- hash
23
+ # Define Table Array
24
+ hash[last_key] = [] unless hash[last_key]
25
+ hash[last_key] << {}
26
+
27
+ hash[last_key].last
16
28
  end
17
29
 
18
30
  def accept_visitor(parser)
@@ -20,7 +20,17 @@ test_string = "You'll hate me after this - #" # " Annoying, isn't it?
20
20
  # ] Oh yes I did
21
21
  ]
22
22
 
23
- [[nested.table.array]]
23
+ [parent.child1]
24
+ key = 'value'
25
+
26
+ [[parent.child2]]
27
+ key2 = 'value'
28
+
29
+ [[parent.child2]]
30
+ key3 = 'value'
31
+
32
+ [[a.b]]
33
+ c = 3
24
34
 
25
35
  # Each of the following keygroups/key value pairs should produce an error. Uncomment to them to test
26
36
 
@@ -109,7 +109,6 @@ class TomlExamples
109
109
  def self.example
110
110
  {
111
111
  'title' => 'TOML Example',
112
-
113
112
  'owner' => {
114
113
  'name' => 'Tom Preston-Werner',
115
114
  'organization' => 'GitHub',
@@ -123,7 +122,6 @@ class TomlExamples
123
122
  'connection_max' => 5000,
124
123
  'enabled' => true
125
124
  },
126
-
127
125
  'servers' => {
128
126
  'alpha' => {
129
127
  'ip' => '10.0.0.1',
@@ -134,7 +132,6 @@ class TomlExamples
134
132
  'dc' => 'eqdc10'
135
133
  }
136
134
  },
137
-
138
135
  'clients' => {
139
136
  'data' => [%w(gamma delta), [1, 2]],
140
137
  'hosts' => %w(alpha omega)
@@ -157,15 +154,18 @@ class TomlExamples
157
154
  }
158
155
  }
159
156
  },
160
- "nested" => [
161
- {
162
- "table" => [
163
- {
164
- "array" => [{}]
165
- }
166
- ]
167
- }
168
- ]
157
+ 'parent' => {
158
+ 'child1' => { 'key' => 'value' },
159
+ 'child2' => [
160
+ { 'key2' => 'value' },
161
+ { 'key3' => 'value' }
162
+ ]
163
+ },
164
+ 'a' => {
165
+ 'b' => [
166
+ { 'c' => 3 }
167
+ ]
168
+ }
169
169
  }
170
170
  end
171
171
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'toml-rb'
3
- s.version = '0.2.0'
3
+ s.version = '0.2.1'
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. '
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.2.0
4
+ version: 0.2.1
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: 2015-01-31 00:00:00.000000000 Z
12
+ date: 2015-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: citrus