toml-rb 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/toml-rb/parser.rb +2 -2
- data/lib/toml-rb/table.rb +8 -6
- data/lib/toml-rb/version.rb +1 -1
- data/lib/toml-rb.rb +14 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd9c5ba72f17c7f6c080cab4a3f67c478f63cc7660da4962dff12f06ce9abc8f
|
4
|
+
data.tar.gz: adc7291b56ea5a442efe533808f8b7fcfe05494c55f73dc554f5ec0e8bb22769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8be2fbd9046868aee722f5edf17451966be58bce14d1c7cc693a7ff3d1735c461b96a769720a3fa599a8e9de649e451dd8b7d2a9cc179122a50b8a3222cfc55
|
7
|
+
data.tar.gz: aa7de16365bf67d983f1aed345e6ed90614209acd6663b525d9ba6621e39283d9e6312a12607e2c60bfb3205b198502cefe15e390eda6b229cef0f9dddfdd9bb
|
data/lib/toml-rb/parser.rb
CHANGED
@@ -2,12 +2,12 @@ module TomlRB
|
|
2
2
|
class Parser
|
3
3
|
attr_reader :hash
|
4
4
|
|
5
|
-
def initialize(content,
|
5
|
+
def initialize(content, symbolize_keys: false)
|
6
6
|
@hash = {}
|
7
7
|
@visited_keys = []
|
8
8
|
@fully_defined_keys = []
|
9
9
|
@current = @hash
|
10
|
-
@symbolize_keys =
|
10
|
+
@symbolize_keys = symbolize_keys
|
11
11
|
|
12
12
|
begin
|
13
13
|
parsed = TomlRB::Document.parse(content)
|
data/lib/toml-rb/table.rb
CHANGED
@@ -18,12 +18,6 @@ module TomlRB
|
|
18
18
|
current
|
19
19
|
end
|
20
20
|
|
21
|
-
# Fail if the key was already defined with a ValueOverwriteError
|
22
|
-
def ensure_key_not_defined(visited_keys)
|
23
|
-
fail ValueOverwriteError.new(full_key) if visited_keys.include?(full_key)
|
24
|
-
visited_keys << full_key
|
25
|
-
end
|
26
|
-
|
27
21
|
def accept_visitor(parser)
|
28
22
|
parser.visit_table self
|
29
23
|
end
|
@@ -31,6 +25,14 @@ module TomlRB
|
|
31
25
|
def full_key
|
32
26
|
@dotted_keys.join(".")
|
33
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# Fail if the key was already defined with a ValueOverwriteError
|
32
|
+
def ensure_key_not_defined(visited_keys)
|
33
|
+
fail ValueOverwriteError.new(full_key) if visited_keys.include?(full_key)
|
34
|
+
visited_keys << full_key
|
35
|
+
end
|
34
36
|
end
|
35
37
|
|
36
38
|
# Used in document.citrus
|
data/lib/toml-rb/version.rb
CHANGED
data/lib/toml-rb.rb
CHANGED
@@ -11,18 +11,18 @@ require_relative "toml-rb/keyvalue"
|
|
11
11
|
require_relative "toml-rb/parser"
|
12
12
|
require_relative "toml-rb/dumper"
|
13
13
|
|
14
|
-
|
15
|
-
Citrus.load "#{
|
16
|
-
Citrus.load "#{
|
17
|
-
Citrus.load "#{
|
18
|
-
Citrus.load "#{
|
14
|
+
File.dirname(File.expand_path(__FILE__)).tap do |root|
|
15
|
+
Citrus.load "#{root}/toml-rb/grammars/helper.citrus"
|
16
|
+
Citrus.load "#{root}/toml-rb/grammars/primitive.citrus"
|
17
|
+
Citrus.load "#{root}/toml-rb/grammars/array.citrus"
|
18
|
+
Citrus.load "#{root}/toml-rb/grammars/document.citrus"
|
19
|
+
end
|
19
20
|
|
20
21
|
module TomlRB
|
21
22
|
# Public: Returns a hash from *TomlRB* content.
|
22
23
|
#
|
23
|
-
# content
|
24
|
-
#
|
25
|
-
# :symbolize_keys - true|false (optional).
|
24
|
+
# content - TomlRB string to be parsed.
|
25
|
+
# :symbolize_keys - true | false (default: false).
|
26
26
|
#
|
27
27
|
#
|
28
28
|
# Examples
|
@@ -43,15 +43,14 @@ module TomlRB
|
|
43
43
|
# Returns a Ruby hash representation of the content according to TomlRB spec.
|
44
44
|
# Raises ValueOverwriteError if a key is overwritten.
|
45
45
|
# Raises ParseError if the content has invalid TomlRB.
|
46
|
-
def self.parse(content,
|
47
|
-
Parser.new(content,
|
46
|
+
def self.parse(content, symbolize_keys: false)
|
47
|
+
Parser.new(content, symbolize_keys: symbolize_keys).hash
|
48
48
|
end
|
49
49
|
|
50
50
|
# Public: Returns a hash from a *TomlRB* file.
|
51
51
|
#
|
52
|
-
# path
|
53
|
-
#
|
54
|
-
# :symbolize_keys - true|false (optional).
|
52
|
+
# path - TomlRB File path
|
53
|
+
# :symbolize_keys - true|false (optional).
|
55
54
|
#
|
56
55
|
#
|
57
56
|
# Examples
|
@@ -68,8 +67,8 @@ module TomlRB
|
|
68
67
|
# Raises ParseError if the content has invalid TomlRB.
|
69
68
|
# Raises Errno::ENOENT if the file cannot be found.
|
70
69
|
# Raises Errno::EACCES if the file cannot be accessed.
|
71
|
-
def self.load_file(path,
|
72
|
-
TomlRB.parse(File.read(path),
|
70
|
+
def self.load_file(path, symbolize_keys: false)
|
71
|
+
TomlRB.parse(File.read(path), symbolize_keys: symbolize_keys)
|
73
72
|
end
|
74
73
|
|
75
74
|
# Public: Returns a *TomlRB* string from a Ruby Hash.
|
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: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emiliano Mancuso
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
- !ruby/object:Gem::Version
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
|
-
rubygems_version: 3.2.
|
121
|
+
rubygems_version: 3.2.30
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Toml parser in ruby, for ruby.
|