hocon 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +24 -2
- data/lib/hocon.rb +30 -4
- data/lib/hocon/config_syntax.rb +2 -0
- data/lib/hocon/config_value_type.rb +1 -1
- data/lib/hocon/impl/from_map_mode.rb +1 -1
- data/lib/hocon/impl/parseable.rb +1 -1
- data/lib/hocon/impl/simple_config.rb +9 -9
- data/lib/hocon/impl/token.rb +1 -1
- data/lib/hocon/impl/token_type.rb +1 -1
- data/lib/hocon/impl/tokens.rb +2 -2
- data/spec/fixtures/hocon/by_extension/cat.conf +4 -0
- data/spec/fixtures/hocon/by_extension/cat.test +4 -0
- data/spec/fixtures/hocon/by_extension/cat.test-json +3 -0
- data/spec/unit/hocon/README.md +7 -0
- data/spec/unit/{typesafe/config → hocon}/hocon_spec.rb +38 -0
- data/spec/unit/typesafe/config/README.md +4 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5f840792a5f3186c9fa371d26249c29160d789f
|
4
|
+
data.tar.gz: b0ef532026b4e0884ba1d17bfe44206835ed3053
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d705bb5985d3a0c1792726de5526272bb46ea28502e25da8b98d171aae1b3c598aa57908ecb56ba76d0c6ae1ca5cc8e941cd4ecf55a69fd2a65e5b0bd6617075
|
7
|
+
data.tar.gz: adcea68d2278b03b1e4ff067a8f615e8c9796574c61dabaad49397cdd8ef81dfb4d60d3aa298a4d6a8ec2c2cd5398195886dd3f69d1d53f1cee4b5bb6539ce47
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 1.1.0
|
2
|
+
This is a bugfix/feature release
|
3
|
+
|
4
|
+
* Fixed a bug where unrecognized config file extensions caused `Hocon.load` to return an empty
|
5
|
+
hash instead of an error.
|
6
|
+
* Added an optional `:syntax` key to the `Hocon.load` method to explicitly specify the file format
|
7
|
+
* Renamed internal usage of `name` methods to avoid overriding built in `Object#name` method
|
8
|
+
|
1
9
|
## 1.0.1
|
2
10
|
|
3
11
|
This is a bugfix release.
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ This is a port of the [Typesafe Config](https://github.com/typesafehub/config) l
|
|
8
8
|
The library provides Ruby support for the [HOCON](https://github.com/typesafehub/config/blob/master/HOCON.md) configuration file format.
|
9
9
|
|
10
10
|
|
11
|
-
At present, it supports
|
11
|
+
At present, it supports parsing and modification of existing HOCON/JSON files via the `ConfigFactory`
|
12
12
|
class and the `ConfigValueFactory` class, and rendering parsed config objects back to a String
|
13
13
|
([see examples below](#basic-usage)). It also supports the parsing and modification of HOCON/JSON files via
|
14
14
|
`ConfigDocumentFactory`.
|
@@ -35,6 +35,22 @@ conf = Hocon.load("myapp.conf")
|
|
35
35
|
puts "Here's a setting: #{conf["foo"]["bar"]["baz"]}"
|
36
36
|
```
|
37
37
|
|
38
|
+
By default, the simple API will determine the configuration file syntax/format
|
39
|
+
based on the filename extension of the file; `.conf` will be interpreted as HOCON,
|
40
|
+
`.json` will be interpreted as strict JSON, and any other extension will cause an
|
41
|
+
error to be raised since the syntax is unknown. If you'd like to use a different
|
42
|
+
file extension, you manually specify the syntax, like this:
|
43
|
+
|
44
|
+
```rb
|
45
|
+
require 'hocon'
|
46
|
+
require 'hocon/config_syntax'
|
47
|
+
|
48
|
+
conf = Hocon.load("myapp.blah", {:syntax => Hocon::ConfigSyntax::HOCON})
|
49
|
+
```
|
50
|
+
|
51
|
+
Supported values for `:syntax` are: JSON, CONF, and HOCON. (CONF and HOCON are
|
52
|
+
aliases, and both map to the underlying HOCON syntax.)
|
53
|
+
|
38
54
|
To use the ConfigDocument API, if you need both read/write capability for
|
39
55
|
modifying settings in a config file, or if you want to retain access to
|
40
56
|
things like comments and line numbers:
|
@@ -61,7 +77,7 @@ Testing
|
|
61
77
|
=======
|
62
78
|
|
63
79
|
```sh
|
64
|
-
bundle install
|
80
|
+
bundle install --path .bundle
|
65
81
|
bundle exec rspec spec
|
66
82
|
```
|
67
83
|
|
@@ -77,3 +93,9 @@ Unsupported features include:
|
|
77
93
|
* Parsing anything other than files and strings
|
78
94
|
* Duration and size settings
|
79
95
|
* Java system properties
|
96
|
+
|
97
|
+
## Maintainence
|
98
|
+
|
99
|
+
Maintainers: Joe Pinsonault <joe.pinsonault@puppet.com>, Chris Price <chris@puppet.com>, Kevin Corcoran <kevin.corcoran@puppet.com>
|
100
|
+
|
101
|
+
Tickets: https://tickets.puppetlabs.com/browse/HC
|
data/lib/hocon.rb
CHANGED
@@ -1,13 +1,39 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Hocon
|
4
|
-
|
5
|
-
|
4
|
+
# NOTE: the behavior of this load method differs a bit from the upstream public
|
5
|
+
# API, where a file extension may be the preferred method of determining
|
6
|
+
# the config syntax, even if you specify a Syntax value on ConfigParseOptions.
|
7
|
+
# Here we prefer the syntax (optionally) specified by the user no matter what
|
8
|
+
# the file extension is, and if they don't specify one and the file extension
|
9
|
+
# is unrecognized, we raise an error.
|
10
|
+
def self.load(file, opts = nil)
|
11
|
+
# doing these requires lazily, because otherwise, classes that need to
|
6
12
|
# `require 'hocon'` to get the module into scope will end up recursing
|
7
13
|
# through this require and probably ending up with circular dependencies.
|
8
14
|
require 'hocon/config_factory'
|
9
|
-
|
10
|
-
|
15
|
+
require 'hocon/impl/parseable'
|
16
|
+
require 'hocon/config_parse_options'
|
17
|
+
require 'hocon/config_resolve_options'
|
18
|
+
require 'hocon/config_error'
|
19
|
+
syntax = opts ? opts[:syntax] : nil
|
20
|
+
|
21
|
+
if syntax.nil?
|
22
|
+
unless Hocon::Impl::Parseable.syntax_from_extension(file)
|
23
|
+
raise Hocon::ConfigError::ConfigParseError.new(
|
24
|
+
nil, "Unrecognized file extension '#{File.extname(file)}' and no value provided for :syntax option", nil)
|
25
|
+
end
|
26
|
+
config = Hocon::ConfigFactory.parse_file_any_syntax(
|
27
|
+
file, Hocon::ConfigParseOptions.defaults)
|
28
|
+
else
|
29
|
+
config = Hocon::ConfigFactory.parse_file(
|
30
|
+
file, Hocon::ConfigParseOptions.defaults.set_syntax(syntax))
|
31
|
+
end
|
32
|
+
|
33
|
+
resolved_config = Hocon::ConfigFactory.load_from_config(
|
34
|
+
config, Hocon::ConfigResolveOptions.defaults)
|
35
|
+
|
36
|
+
return resolved_config.root.unwrapped
|
11
37
|
end
|
12
38
|
|
13
39
|
def self.parse(string)
|
data/lib/hocon/config_syntax.rb
CHANGED
@@ -8,7 +8,7 @@ module Hocon::Impl::FromMapMode
|
|
8
8
|
KEYS_ARE_KEYS = 1
|
9
9
|
ConfigBugOrBrokenError = Hocon::ConfigError::ConfigBugOrBrokenError
|
10
10
|
|
11
|
-
def self.
|
11
|
+
def self.map_mode_name(from_map_mode)
|
12
12
|
case from_map_mode
|
13
13
|
when KEYS_ARE_PATHS then "KEYS_ARE_PATHS"
|
14
14
|
when KEYS_ARE_KEYS then "KEYS_ARE_KEYS"
|
data/lib/hocon/impl/parseable.rb
CHANGED
@@ -61,12 +61,12 @@ class Hocon::Impl::SimpleConfig
|
|
61
61
|
if v.value_type == ConfigValueType::NULL
|
62
62
|
raise ConfigNullError.new(v.origin,
|
63
63
|
(ConfigNullError.make_message(original_path.render,
|
64
|
-
(not expected.nil?) ? ConfigValueType.
|
64
|
+
(not expected.nil?) ? ConfigValueType.value_type_name(expected) : nil)),
|
65
65
|
nil)
|
66
66
|
elsif (not expected.nil?) && v.value_type != expected
|
67
67
|
raise ConfigWrongTypeError.new(v.origin,
|
68
|
-
"#{original_path.render} has type #{ConfigValueType.
|
69
|
-
"rather than #{ConfigValueType.
|
68
|
+
"#{original_path.render} has type #{ConfigValueType.value_type_name(v.value_type)} " +
|
69
|
+
"rather than #{ConfigValueType.value_type_name(expected)}",
|
70
70
|
nil)
|
71
71
|
else
|
72
72
|
return v
|
@@ -121,8 +121,8 @@ class Hocon::Impl::SimpleConfig
|
|
121
121
|
if (not expected.nil?) && (v.value_type != expected && v.value_type != Hocon::ConfigValueType::NULL)
|
122
122
|
raise Hocon::ConfigError::ConfigWrongTypeError.with_expected_actual(v.origin,
|
123
123
|
original_path.render,
|
124
|
-
expected.
|
125
|
-
Hocon::ConfigValueType.
|
124
|
+
expected.value_type_name,
|
125
|
+
Hocon::ConfigValueType.value_type_name(v.value_type))
|
126
126
|
else
|
127
127
|
return v
|
128
128
|
end
|
@@ -220,8 +220,8 @@ class Hocon::Impl::SimpleConfig
|
|
220
220
|
end
|
221
221
|
if v.value_type != expected
|
222
222
|
raise ConfigWrongTypeError.with_expected_actual(origin, path,
|
223
|
-
"list of #{expected.
|
224
|
-
"list of #{v.value_type.
|
223
|
+
"list of #{expected.value_type_name}",
|
224
|
+
"list of #{v.value_type.value_type_name}")
|
225
225
|
end
|
226
226
|
l << v.unwrapped
|
227
227
|
end
|
@@ -271,8 +271,8 @@ class Hocon::Impl::SimpleConfig
|
|
271
271
|
end
|
272
272
|
if v.value_type != expected
|
273
273
|
raise ConfigWrongTypeError.with_expected_actual(origin, path,
|
274
|
-
"list of #{expected.
|
275
|
-
"list of #{v.value_type.
|
274
|
+
"list of #{expected.value_type_name}",
|
275
|
+
"list of #{v.value_type.value_type_name}")
|
276
276
|
end
|
277
277
|
l << v
|
278
278
|
end
|
data/lib/hocon/impl/token.rb
CHANGED
data/lib/hocon/impl/tokens.rb
CHANGED
@@ -35,9 +35,9 @@ class Hocon::Impl::Tokens
|
|
35
35
|
|
36
36
|
def to_s
|
37
37
|
if value.resolve_status == ResolveStatus::RESOLVED
|
38
|
-
"'#{value.unwrapped}' (#{Hocon::ConfigValueType.
|
38
|
+
"'#{value.unwrapped}' (#{Hocon::ConfigValueType.value_type_name(value.value_type)})"
|
39
39
|
else
|
40
|
-
"'<unresolved value>' (#{@value.value_type.
|
40
|
+
"'<unresolved value>' (#{@value.value_type.value_type_name})"
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
## RUBY-SPECIFIC TESTS
|
2
|
+
|
3
|
+
This directory should only contain tests that are specific to the Ruby library/API.
|
4
|
+
Tests ported from the upstream Java library should live in spec/typesafe/config.
|
5
|
+
|
6
|
+
Where possible it would be good to avoid sharing fixtures between the two types
|
7
|
+
of tests as well.
|
@@ -3,6 +3,10 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require 'hocon'
|
5
5
|
require 'hocon/config_render_options'
|
6
|
+
require 'hocon/config_error'
|
7
|
+
require 'hocon/config_syntax'
|
8
|
+
|
9
|
+
ConfigParseError = Hocon::ConfigError::ConfigParseError
|
6
10
|
|
7
11
|
describe Hocon do
|
8
12
|
let(:render_options) { Hocon::ConfigRenderOptions.defaults }
|
@@ -50,5 +54,39 @@ describe Hocon do
|
|
50
54
|
expect(conf).to eq(expected)
|
51
55
|
end
|
52
56
|
end
|
57
|
+
|
58
|
+
context "loading a file with an unknown extension" do
|
59
|
+
context "without specifying the config format" do
|
60
|
+
it "should raise an error" do
|
61
|
+
expect {
|
62
|
+
Hocon.load("#{FIXTURE_DIR}/hocon/by_extension/cat.test")
|
63
|
+
}.to raise_error(ConfigParseError, /Unrecognized file extension '.test'/)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "while specifying the config format" do
|
68
|
+
it "should parse properly if the config format is correct" do
|
69
|
+
expect(Hocon.load("#{FIXTURE_DIR}/hocon/by_extension/cat.test",
|
70
|
+
{:syntax => Hocon::ConfigSyntax::HOCON})).
|
71
|
+
to eq({"meow" => "cats"})
|
72
|
+
expect(Hocon.load("#{FIXTURE_DIR}/hocon/by_extension/cat.test-json",
|
73
|
+
{:syntax => Hocon::ConfigSyntax::HOCON})).
|
74
|
+
to eq({"meow" => "cats"})
|
75
|
+
end
|
76
|
+
it "should parse properly if the config format is compatible" do
|
77
|
+
expect(Hocon.load("#{FIXTURE_DIR}/hocon/by_extension/cat.test-json",
|
78
|
+
{:syntax => Hocon::ConfigSyntax::JSON})).
|
79
|
+
to eq({"meow" => "cats"})
|
80
|
+
end
|
81
|
+
it "should raise an error if the config format is incompatible" do
|
82
|
+
expect {
|
83
|
+
Hocon.load("#{FIXTURE_DIR}/hocon/by_extension/cat.test",
|
84
|
+
{:syntax => Hocon::ConfigSyntax::JSON})
|
85
|
+
}.to raise_error(ConfigParseError, /Document must have an object or array at root/)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
53
91
|
end
|
54
92
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hocon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Price
|
@@ -138,6 +138,9 @@ files:
|
|
138
138
|
- lib/hocon/parser/config_document.rb
|
139
139
|
- lib/hocon/parser/config_document_factory.rb
|
140
140
|
- lib/hocon/parser/config_node.rb
|
141
|
+
- spec/fixtures/hocon/by_extension/cat.conf
|
142
|
+
- spec/fixtures/hocon/by_extension/cat.test
|
143
|
+
- spec/fixtures/hocon/by_extension/cat.test-json
|
141
144
|
- spec/fixtures/parse_render/example1/input.conf
|
142
145
|
- spec/fixtures/parse_render/example1/output.conf
|
143
146
|
- spec/fixtures/parse_render/example1/output_nocomments.conf
|
@@ -160,6 +163,9 @@ files:
|
|
160
163
|
- spec/fixtures/test_utils/resources/test03.conf
|
161
164
|
- spec/spec_helper.rb
|
162
165
|
- spec/test_utils.rb
|
166
|
+
- spec/unit/hocon/README.md
|
167
|
+
- spec/unit/hocon/hocon_spec.rb
|
168
|
+
- spec/unit/typesafe/config/README.md
|
163
169
|
- spec/unit/typesafe/config/concatenation_spec.rb
|
164
170
|
- spec/unit/typesafe/config/conf_parser_spec.rb
|
165
171
|
- spec/unit/typesafe/config/config_document_parser_spec.rb
|
@@ -168,7 +174,6 @@ files:
|
|
168
174
|
- spec/unit/typesafe/config/config_node_spec.rb
|
169
175
|
- spec/unit/typesafe/config/config_value_factory_spec.rb
|
170
176
|
- spec/unit/typesafe/config/config_value_spec.rb
|
171
|
-
- spec/unit/typesafe/config/hocon_spec.rb
|
172
177
|
- spec/unit/typesafe/config/path_spec.rb
|
173
178
|
- spec/unit/typesafe/config/public_api_spec.rb
|
174
179
|
- spec/unit/typesafe/config/simple_config_spec.rb
|
@@ -194,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
199
|
version: '0'
|
195
200
|
requirements: []
|
196
201
|
rubyforge_project:
|
197
|
-
rubygems_version: 2.5.
|
202
|
+
rubygems_version: 2.5.1
|
198
203
|
signing_key:
|
199
204
|
specification_version: 4
|
200
205
|
summary: HOCON Config Library
|