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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa50386bfa3e4b6410b0339e2e24ea0e7ebef6e9c5ad5d6616bb1866c6603fb5
4
- data.tar.gz: 636e0c4c7a3587958eebbcec87a0284c0aa85607e5e16a894ff4d9b3d884120f
3
+ metadata.gz: cd9c5ba72f17c7f6c080cab4a3f67c478f63cc7660da4962dff12f06ce9abc8f
4
+ data.tar.gz: adc7291b56ea5a442efe533808f8b7fcfe05494c55f73dc554f5ec0e8bb22769
5
5
  SHA512:
6
- metadata.gz: d2d14285ee0ad9f55a8473354936f7398d62ee2a3ffca01609c420ebd809e5672506224158f41025f8defe7ab962de51830c30897483b9a2559d6438633b5197
7
- data.tar.gz: 2ffba44e31838a5e46a579415240f14e9c7cdab6862658abff83e87913c10a1145711112ffd8e990599a83b6161a2ccacadd303ba1b8e3b9a01ca62679df2b06
6
+ metadata.gz: a8be2fbd9046868aee722f5edf17451966be58bce14d1c7cc693a7ff3d1735c461b96a769720a3fa599a8e9de649e451dd8b7d2a9cc179122a50b8a3222cfc55
7
+ data.tar.gz: aa7de16365bf67d983f1aed345e6ed90614209acd6663b525d9ba6621e39283d9e6312a12607e2c60bfb3205b198502cefe15e390eda6b229cef0f9dddfdd9bb
@@ -2,12 +2,12 @@ module TomlRB
2
2
  class Parser
3
3
  attr_reader :hash
4
4
 
5
- def initialize(content, options = {})
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 = options[: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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TomlRB
4
- VERSION = "2.0.2"
4
+ VERSION = "2.1.0"
5
5
  end
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
- ROOT = File.dirname(File.expand_path(__FILE__))
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"
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 - TomlRB string to be parsed.
24
- # options - The Hash options used to refine the parser (default: {}):
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, options = {})
47
- Parser.new(content, options).hash
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 - TomlRB File path
53
- # options - The Hash options used to refine the parser (default: {}):
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, options = {})
72
- TomlRB.parse(File.read(path), options)
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.2
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.22
121
+ rubygems_version: 3.2.30
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: Toml parser in ruby, for ruby.