hocon 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -0
- data/lib/hocon.rb +10 -2
- data/lib/hocon/config_error.rb +31 -9
- data/lib/hocon/config_factory.rb +7 -9
- data/lib/hocon/config_object.rb +4 -4
- data/lib/hocon/config_parse_options.rb +43 -43
- data/lib/hocon/config_render_options.rb +41 -41
- data/lib/hocon/config_syntax.rb +7 -7
- data/lib/hocon/config_value_factory.rb +10 -0
- data/lib/hocon/config_value_type.rb +23 -23
- data/lib/hocon/impl.rb +5 -4
- data/lib/hocon/impl/abstract_config_object.rb +49 -0
- data/lib/hocon/impl/abstract_config_value.rb +16 -0
- data/lib/hocon/impl/config_boolean.rb +25 -0
- data/lib/hocon/impl/config_float.rb +4 -0
- data/lib/hocon/impl/config_impl.rb +125 -0
- data/lib/hocon/impl/config_impl_util.rb +8 -0
- data/lib/hocon/impl/config_null.rb +25 -0
- data/lib/hocon/impl/default_transformer.rb +97 -0
- data/lib/hocon/impl/from_map_mode.rb +16 -0
- data/lib/hocon/impl/parser.rb +185 -92
- data/lib/hocon/impl/path.rb +77 -0
- data/lib/hocon/impl/path_builder.rb +1 -2
- data/lib/hocon/impl/properties_parser.rb +83 -0
- data/lib/hocon/impl/simple_config.rb +76 -0
- data/lib/hocon/impl/simple_config_list.rb +1 -0
- data/lib/hocon/impl/simple_config_object.rb +67 -0
- data/lib/hocon/impl/tokenizer.rb +8 -0
- data/lib/hocon/impl/tokens.rb +7 -1
- metadata +59 -15
- checksums.yaml +0 -7
data/README.md
CHANGED
data/lib/hocon.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
-
require 'hocon/config_factory'
|
2
|
-
|
3
1
|
module Hocon
|
2
|
+
require 'hocon/config_factory'
|
3
|
+
require 'hocon/config_parse_options'
|
4
|
+
require 'hocon/config_error'
|
5
|
+
require 'hocon/config_object'
|
6
|
+
require 'hocon/config_parse_options'
|
7
|
+
require 'hocon/config_render_options'
|
8
|
+
require 'hocon/config_syntax'
|
9
|
+
require 'hocon/config_value_factory'
|
10
|
+
require 'hocon/config_value_type'
|
11
|
+
|
4
12
|
def self.load(file)
|
5
13
|
config = Hocon::ConfigFactory.parse_file(file)
|
6
14
|
return config.root.unwrapped
|
data/lib/hocon/config_error.rb
CHANGED
@@ -1,15 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
require 'hocon'
|
2
|
+
|
3
|
+
class Hocon::ConfigError < StandardError
|
4
|
+
def initialize(origin, message, cause)
|
5
|
+
super(message)
|
6
|
+
@origin = origin
|
7
|
+
@cause = cause
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
+
class ConfigMissingError < Hocon::ConfigError
|
11
|
+
end
|
12
|
+
|
13
|
+
class ConfigNullError < Hocon::ConfigError::ConfigMissingError
|
14
|
+
def self.make_message(path, expected)
|
15
|
+
if not expected.nil?
|
16
|
+
"Configuration key '#{path}' is set to nil but expected #{expected}"
|
17
|
+
else
|
18
|
+
"Configuration key '#{path}' is nil"
|
19
|
+
end
|
10
20
|
end
|
21
|
+
end
|
11
22
|
|
12
|
-
|
23
|
+
class ConfigParseError < Hocon::ConfigError
|
24
|
+
end
|
25
|
+
|
26
|
+
class ConfigWrongTypeError < Hocon::ConfigError
|
27
|
+
end
|
28
|
+
|
29
|
+
class ConfigBugOrBrokenError < Hocon::ConfigError
|
30
|
+
def initialize(message, cause)
|
31
|
+
super(nil, message, cause)
|
13
32
|
end
|
14
33
|
end
|
34
|
+
|
35
|
+
class ConfigNotResolvedError < Hocon::ConfigError::ConfigBugOrBrokenError
|
36
|
+
end
|
15
37
|
end
|
data/lib/hocon/config_factory.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
require 'hocon
|
1
|
+
require 'hocon'
|
2
2
|
require 'hocon/impl/parseable'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
4
|
+
class Hocon::ConfigFactory
|
5
|
+
def self.parse_file(file_path, options = Hocon::ConfigParseOptions.defaults)
|
6
|
+
Hocon::Impl::Parseable.new_file(file_path, options).parse.to_config
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
9
|
+
def self.parse_string(string, options = Hocon::ConfigParseOptions.defaults)
|
10
|
+
Hocon::Impl::Parseable.new_string(string, options).parse.to_config
|
13
11
|
end
|
14
12
|
end
|
data/lib/hocon/config_object.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
end
|
1
|
+
require 'hocon'
|
2
|
+
|
3
|
+
module Hocon::ConfigObject
|
4
|
+
end
|
@@ -1,53 +1,53 @@
|
|
1
|
-
|
2
|
-
class ConfigParseOptions
|
3
|
-
attr_accessor :syntax, :origin_description, :allow_missing, :includer
|
1
|
+
require 'hocon'
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
class Hocon::ConfigParseOptions
|
4
|
+
attr_accessor :syntax, :origin_description, :allow_missing, :includer
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@allow_missing = allow_missing
|
13
|
-
@includer = includer
|
14
|
-
end
|
6
|
+
def self.defaults
|
7
|
+
self.new(nil, nil, true, nil)
|
8
|
+
end
|
15
9
|
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
def initialize(syntax, origin_description, allow_missing, includer)
|
11
|
+
@syntax = syntax
|
12
|
+
@origin_description = origin_description
|
13
|
+
@allow_missing = allow_missing
|
14
|
+
@includer = includer
|
15
|
+
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
else
|
24
|
-
Hocon::ConfigParseOptions.new(syntax,
|
25
|
-
@origin_description,
|
26
|
-
@allow_missing,
|
27
|
-
@includer)
|
28
|
-
end
|
29
|
-
end
|
17
|
+
def allow_missing?
|
18
|
+
@allow_missing
|
19
|
+
end
|
30
20
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
21
|
+
def with_syntax(syntax)
|
22
|
+
if @syntax == syntax
|
23
|
+
self
|
24
|
+
else
|
25
|
+
Hocon::ConfigParseOptions.new(syntax,
|
26
|
+
@origin_description,
|
27
|
+
@allow_missing,
|
28
|
+
@includer)
|
40
29
|
end
|
30
|
+
end
|
41
31
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
32
|
+
def with_includer(includer)
|
33
|
+
if @includer == includer
|
34
|
+
self
|
35
|
+
else
|
36
|
+
Hocon::ConfigParseOptions.new(@syntax,
|
37
|
+
@origin_description,
|
38
|
+
@allow_missing,
|
39
|
+
includer)
|
50
40
|
end
|
41
|
+
end
|
51
42
|
|
43
|
+
def append_includer(includer)
|
44
|
+
if @includer == includer
|
45
|
+
self
|
46
|
+
elsif @includer
|
47
|
+
with_includer(@includer.with_fallback(includer))
|
48
|
+
else
|
49
|
+
with_includer(includer)
|
50
|
+
end
|
52
51
|
end
|
53
|
-
|
52
|
+
|
53
|
+
end
|
@@ -1,46 +1,46 @@
|
|
1
|
-
|
2
|
-
class ConfigRenderOptions
|
3
|
-
def initialize(origin_comments, comments, formatted, json)
|
4
|
-
@origin_comments = origin_comments
|
5
|
-
@comments = comments
|
6
|
-
@formatted = formatted
|
7
|
-
@json = json
|
8
|
-
end
|
1
|
+
require 'hocon'
|
9
2
|
|
10
|
-
|
3
|
+
class Hocon::ConfigRenderOptions
|
4
|
+
def initialize(origin_comments, comments, formatted, json)
|
5
|
+
@origin_comments = origin_comments
|
6
|
+
@comments = comments
|
7
|
+
@formatted = formatted
|
8
|
+
@json = json
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
@origin_comments
|
14
|
-
end
|
15
|
-
def comments?
|
16
|
-
@comments
|
17
|
-
end
|
18
|
-
def formatted?
|
19
|
-
@formatted
|
20
|
-
end
|
21
|
-
def json?
|
22
|
-
@json
|
23
|
-
end
|
11
|
+
attr_writer :origin_comments, :comments, :formatted, :json
|
24
12
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
13
|
+
def origin_comments?
|
14
|
+
@origin_comments
|
15
|
+
end
|
16
|
+
def comments?
|
17
|
+
@comments
|
18
|
+
end
|
19
|
+
def formatted?
|
20
|
+
@formatted
|
21
|
+
end
|
22
|
+
def json?
|
23
|
+
@json
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Returns the default render options which are verbose (commented and
|
28
|
+
# formatted). See {@link ConfigRenderOptions#concise} for stripped-down
|
29
|
+
# options. This rendering will not be valid JSON since it has comments.
|
30
|
+
#
|
31
|
+
# @return the default render options
|
32
|
+
#
|
33
|
+
def self.defaults
|
34
|
+
Hocon::ConfigRenderOptions.new(true, true, true, true)
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
37
|
+
#
|
38
|
+
# Returns concise render options (no whitespace or comments). For a
|
39
|
+
# resolved {@link Config}, the concise rendering will be valid JSON.
|
40
|
+
#
|
41
|
+
# @return the concise render options
|
42
|
+
#
|
43
|
+
def self.concise
|
44
|
+
Hocon::ConfigRenderOptions.new(false, false, false, true)
|
45
45
|
end
|
46
|
-
end
|
46
|
+
end
|
data/lib/hocon/config_syntax.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
1
|
+
require 'hocon'
|
2
|
+
|
3
|
+
module Hocon::ConfigSyntax
|
4
|
+
JSON = 0
|
5
|
+
CONF = 1
|
6
|
+
PROPERTIES = 2
|
7
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# The type of a configuration value (following the <a
|
4
|
-
# href="http://json.org">JSON</a> type schema).
|
5
|
-
#
|
6
|
-
module ConfigValueType
|
7
|
-
OBJECT = 0
|
8
|
-
LIST = 1
|
9
|
-
NUMBER = 2
|
10
|
-
BOOLEAN = 3
|
11
|
-
NULL = 4
|
12
|
-
STRING = 5
|
1
|
+
require 'hocon'
|
13
2
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
3
|
+
#
|
4
|
+
# The type of a configuration value (following the <a
|
5
|
+
# href="http://json.org">JSON</a> type schema).
|
6
|
+
#
|
7
|
+
module Hocon::ConfigValueType
|
8
|
+
OBJECT = 0
|
9
|
+
LIST = 1
|
10
|
+
NUMBER = 2
|
11
|
+
BOOLEAN = 3
|
12
|
+
NULL = 4
|
13
|
+
STRING = 5
|
14
|
+
|
15
|
+
def self.name(config_value_type)
|
16
|
+
case config_value_type
|
17
|
+
when OBJECT then "OBJECT"
|
18
|
+
when LIST then "LIST"
|
19
|
+
when NUMBER then "NUMBER"
|
20
|
+
when BOOLEAN then "BOOLEAN"
|
21
|
+
when NULL then "NULL"
|
22
|
+
when STRING then "STRING"
|
23
|
+
else raise ConfigBugError, "Unrecognized value type '#{config_value_type}'"
|
24
24
|
end
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
data/lib/hocon/impl.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'hocon'
|
2
|
+
|
3
|
+
module Hocon::Impl
|
4
|
+
|
5
|
+
end
|
@@ -5,10 +5,15 @@ require 'hocon/config_object'
|
|
5
5
|
require 'hocon/config_value_type'
|
6
6
|
require 'hocon/impl/resolve_status'
|
7
7
|
require 'hocon/impl/simple_config_origin'
|
8
|
+
require 'hocon/config_error'
|
9
|
+
require 'hocon/impl/config_impl'
|
8
10
|
|
9
11
|
class Hocon::Impl::AbstractConfigObject < Hocon::Impl::AbstractConfigValue
|
10
12
|
include Hocon::ConfigObject
|
11
13
|
|
14
|
+
ConfigBugOrBrokenError = Hocon::ConfigError::ConfigBugOrBrokenError
|
15
|
+
ConfigNotResolvedError = Hocon::ConfigError::ConfigNotResolvedError
|
16
|
+
|
12
17
|
def initialize(origin)
|
13
18
|
super(origin)
|
14
19
|
@config = Hocon::Impl::SimpleConfig.new(self)
|
@@ -61,4 +66,48 @@ class Hocon::Impl::AbstractConfigObject < Hocon::Impl::AbstractConfigValue
|
|
61
66
|
|
62
67
|
Hocon::Impl::SimpleConfigOrigin.merge_origins(origins)
|
63
68
|
end
|
69
|
+
|
70
|
+
def peek_assuming_resolved(key, original_path)
|
71
|
+
begin
|
72
|
+
attempt_peek_with_partial_resolve(key)
|
73
|
+
rescue ConfigNotResolvedError => e
|
74
|
+
raise Hocon::Impl::ConfigImpl.improve_not_resolved(original_path, e)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def peek_path(path)
|
79
|
+
begin
|
80
|
+
return peek_path_impl(self, path, nil)
|
81
|
+
rescue ConfigNotResolvedError => e
|
82
|
+
raise ConfigBugOrBrokenError.new("NotPossibleToResolve happened though we had no ResolveContext in peek_path", nil)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def peek_path_impl(me, path, context)
|
87
|
+
begin
|
88
|
+
if not context.nil?
|
89
|
+
partially_resolved = context.restrict(path).resolve(me)
|
90
|
+
if partially_resolved.is_a?(self.class)
|
91
|
+
return peek_path_impl(partially_resolved, path, nil)
|
92
|
+
else
|
93
|
+
raise ConfigBugOrBrokenError.new(
|
94
|
+
"resolved object to non-object #{me} to #{partially_resolved}", nil)
|
95
|
+
end
|
96
|
+
else
|
97
|
+
remainder = path.remainder
|
98
|
+
v = me.attempt_peek_with_partial_resolve(path.first)
|
99
|
+
if remainder.nil?
|
100
|
+
return v
|
101
|
+
else
|
102
|
+
if v.is_a?(self.class)
|
103
|
+
return peek_path_impl(v, remainder, nil)
|
104
|
+
else
|
105
|
+
return nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
rescue ConfigNotResolvedError => e
|
110
|
+
raise Hocon::Impl::ConfigImpl.improve_not_resolved(path, e)
|
111
|
+
end
|
112
|
+
end
|
64
113
|
end
|