hocon 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +4 -2
- data/lib/hocon.rb +2 -0
- data/lib/hocon/config.rb +1010 -0
- data/lib/hocon/config_error.rb +32 -2
- data/lib/hocon/config_factory.rb +46 -0
- data/lib/hocon/config_include_context.rb +49 -0
- data/lib/hocon/config_includer_file.rb +27 -0
- data/lib/hocon/config_list.rb +49 -0
- data/lib/hocon/config_mergeable.rb +74 -0
- data/lib/hocon/config_object.rb +144 -1
- data/lib/hocon/config_parse_options.rb +33 -9
- data/lib/hocon/config_parseable.rb +51 -0
- data/lib/hocon/config_render_options.rb +4 -2
- data/lib/hocon/config_resolve_options.rb +31 -0
- data/lib/hocon/config_syntax.rb +5 -2
- data/lib/hocon/config_util.rb +73 -0
- data/lib/hocon/config_value.rb +122 -0
- data/lib/hocon/config_value_factory.rb +66 -2
- data/lib/hocon/config_value_type.rb +5 -2
- data/lib/hocon/impl.rb +2 -0
- data/lib/hocon/impl/abstract_config_node.rb +29 -0
- data/lib/hocon/impl/abstract_config_node_value.rb +11 -0
- data/lib/hocon/impl/abstract_config_object.rb +148 -42
- data/lib/hocon/impl/abstract_config_value.rb +251 -11
- data/lib/hocon/impl/array_iterator.rb +19 -0
- data/lib/hocon/impl/config_boolean.rb +7 -1
- data/lib/hocon/impl/config_concatenation.rb +177 -28
- data/lib/hocon/impl/config_delayed_merge.rb +329 -0
- data/lib/hocon/impl/config_delayed_merge_object.rb +274 -0
- data/lib/hocon/impl/config_document_parser.rb +647 -0
- data/lib/hocon/impl/config_double.rb +44 -0
- data/lib/hocon/impl/config_impl.rb +143 -19
- data/lib/hocon/impl/config_impl_util.rb +18 -0
- data/lib/hocon/impl/config_include_kind.rb +10 -0
- data/lib/hocon/impl/config_int.rb +13 -1
- data/lib/hocon/impl/config_node_array.rb +11 -0
- data/lib/hocon/impl/config_node_comment.rb +19 -0
- data/lib/hocon/impl/config_node_complex_value.rb +54 -0
- data/lib/hocon/impl/config_node_concatenation.rb +11 -0
- data/lib/hocon/impl/config_node_field.rb +81 -0
- data/lib/hocon/impl/config_node_include.rb +33 -0
- data/lib/hocon/impl/config_node_object.rb +276 -0
- data/lib/hocon/impl/config_node_path.rb +48 -0
- data/lib/hocon/impl/config_node_root.rb +60 -0
- data/lib/hocon/impl/config_node_simple_value.rb +42 -0
- data/lib/hocon/impl/config_node_single_token.rb +17 -0
- data/lib/hocon/impl/config_null.rb +15 -7
- data/lib/hocon/impl/config_number.rb +43 -4
- data/lib/hocon/impl/config_parser.rb +403 -0
- data/lib/hocon/impl/config_reference.rb +142 -0
- data/lib/hocon/impl/config_string.rb +55 -7
- data/lib/hocon/impl/container.rb +29 -0
- data/lib/hocon/impl/default_transformer.rb +24 -15
- data/lib/hocon/impl/from_map_mode.rb +3 -1
- data/lib/hocon/impl/full_includer.rb +2 -0
- data/lib/hocon/impl/memo_key.rb +42 -0
- data/lib/hocon/impl/mergeable_value.rb +8 -0
- data/lib/hocon/impl/origin_type.rb +8 -2
- data/lib/hocon/impl/parseable.rb +455 -91
- data/lib/hocon/impl/path.rb +181 -59
- data/lib/hocon/impl/path_builder.rb +24 -3
- data/lib/hocon/impl/path_parser.rb +280 -0
- data/lib/hocon/impl/replaceable_merge_stack.rb +22 -0
- data/lib/hocon/impl/resolve_context.rb +254 -0
- data/lib/hocon/impl/resolve_memos.rb +21 -0
- data/lib/hocon/impl/resolve_result.rb +39 -0
- data/lib/hocon/impl/resolve_source.rb +354 -0
- data/lib/hocon/impl/resolve_status.rb +3 -1
- data/lib/hocon/impl/simple_config.rb +264 -10
- data/lib/hocon/impl/simple_config_document.rb +48 -0
- data/lib/hocon/impl/simple_config_list.rb +282 -8
- data/lib/hocon/impl/simple_config_object.rb +424 -88
- data/lib/hocon/impl/simple_config_origin.rb +263 -71
- data/lib/hocon/impl/simple_include_context.rb +31 -1
- data/lib/hocon/impl/simple_includer.rb +196 -1
- data/lib/hocon/impl/substitution_expression.rb +38 -0
- data/lib/hocon/impl/token.rb +17 -4
- data/lib/hocon/impl/token_type.rb +6 -2
- data/lib/hocon/impl/tokenizer.rb +339 -109
- data/lib/hocon/impl/tokens.rb +330 -79
- data/lib/hocon/impl/unmergeable.rb +14 -1
- data/lib/hocon/impl/unsupported_operation_error.rb +6 -0
- data/lib/hocon/impl/url.rb +37 -0
- data/lib/hocon/parser.rb +7 -0
- data/lib/hocon/parser/config_document.rb +92 -0
- data/lib/hocon/parser/config_document_factory.rb +36 -0
- data/lib/hocon/parser/config_node.rb +30 -0
- metadata +67 -43
- data/lib/hocon/impl/config_float.rb +0 -13
- data/lib/hocon/impl/parser.rb +0 -977
- data/lib/hocon/impl/properties_parser.rb +0 -83
data/lib/hocon/config_error.rb
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'hocon'
|
2
4
|
|
3
5
|
class Hocon::ConfigError < StandardError
|
4
6
|
def initialize(origin, message, cause)
|
5
|
-
|
7
|
+
msg =
|
8
|
+
if origin.nil?
|
9
|
+
message
|
10
|
+
else
|
11
|
+
"#{origin.description}: #{message}"
|
12
|
+
end
|
13
|
+
super(msg)
|
6
14
|
@origin = origin
|
7
15
|
@cause = cause
|
8
16
|
end
|
@@ -20,18 +28,40 @@ class Hocon::ConfigError < StandardError
|
|
20
28
|
end
|
21
29
|
end
|
22
30
|
|
31
|
+
class ConfigIOError < Hocon::ConfigError
|
32
|
+
def initialize(origin, message, cause = nil)
|
33
|
+
super(origin, message, cause)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
23
37
|
class ConfigParseError < Hocon::ConfigError
|
24
38
|
end
|
25
39
|
|
26
40
|
class ConfigWrongTypeError < Hocon::ConfigError
|
41
|
+
def self.with_expected_actual(origin, path, expected, actual, cause = nil)
|
42
|
+
ConfigWrongTypeError.new(origin, "#{path} has type #{actual} rather than #{expected}", cause)
|
43
|
+
end
|
27
44
|
end
|
28
45
|
|
29
46
|
class ConfigBugOrBrokenError < Hocon::ConfigError
|
30
|
-
def initialize(message, cause)
|
47
|
+
def initialize(message, cause = nil)
|
31
48
|
super(nil, message, cause)
|
32
49
|
end
|
33
50
|
end
|
34
51
|
|
35
52
|
class ConfigNotResolvedError < Hocon::ConfigError::ConfigBugOrBrokenError
|
36
53
|
end
|
54
|
+
|
55
|
+
class ConfigBadPathError < Hocon::ConfigError
|
56
|
+
def initialize(origin, path, message, cause = nil)
|
57
|
+
error_message = !path.nil? ? "Invalid path '#{path}': #{message}" : message
|
58
|
+
super(origin, error_message, cause)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class UnresolvedSubstitutionError < ConfigParseError
|
63
|
+
def initialize(origin, detail, cause = nil)
|
64
|
+
super(origin, "Could not resolve substitution to a value: " + detail, cause)
|
65
|
+
end
|
66
|
+
end
|
37
67
|
end
|
data/lib/hocon/config_factory.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'hocon'
|
2
4
|
require 'hocon/impl/parseable'
|
3
5
|
require 'hocon/config_parse_options'
|
6
|
+
require 'hocon/impl/config_impl'
|
7
|
+
require 'hocon/config_factory'
|
4
8
|
|
5
9
|
class Hocon::ConfigFactory
|
6
10
|
def self.parse_file(file_path, options = Hocon::ConfigParseOptions.defaults)
|
@@ -10,4 +14,46 @@ class Hocon::ConfigFactory
|
|
10
14
|
def self.parse_string(string, options = Hocon::ConfigParseOptions.defaults)
|
11
15
|
Hocon::Impl::Parseable.new_string(string, options).parse.to_config
|
12
16
|
end
|
17
|
+
|
18
|
+
def self.parse_file_any_syntax(file_base_name, options)
|
19
|
+
Hocon::Impl::ConfigImpl.parse_file_any_syntax(file_base_name, options).to_config
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.empty(origin_description = nil)
|
23
|
+
Hocon::Impl::ConfigImpl.empty_config(origin_description)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Because of how optional arguments work, if either parse or resolve options is supplied
|
27
|
+
# both must be supplied. load_file_with_parse_options or load_file_with_resolve_options
|
28
|
+
# can be used instead, or the argument you don't care about in load_file can be nil
|
29
|
+
#
|
30
|
+
# e.g.:
|
31
|
+
# load_file("settings", my_parse_options, nil)
|
32
|
+
# is equivalent to:
|
33
|
+
# load_file_with_parse_options("settings", my_parse_options)
|
34
|
+
def self.load_file(file_base_name, parse_options = nil, resolve_options = nil)
|
35
|
+
parse_options ||= Hocon::ConfigParseOptions.defaults
|
36
|
+
resolve_options ||= Hocon::ConfigResolveOptions.defaults
|
37
|
+
|
38
|
+
config = Hocon::ConfigFactory.parse_file_any_syntax(file_base_name, parse_options)
|
39
|
+
|
40
|
+
self.load_from_config(config, resolve_options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.load_file_with_parse_options(file_base_name, parse_options)
|
44
|
+
self.load_file(file_base_name, parse_options, nil)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.load_file_with_resolve_options(file_base_name, resolve_options)
|
48
|
+
self.load_file(file_base_name, nil, resolve_options)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.load_from_config(config, resolve_options)
|
52
|
+
|
53
|
+
config.with_fallback(self.default_reference).resolve(resolve_options)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.default_reference
|
57
|
+
Hocon::Impl::ConfigImpl.default_reference
|
58
|
+
end
|
13
59
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'hocon'
|
4
|
+
require 'hocon/config_error'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Context provided to a {@link ConfigIncluder}; this interface is only useful
|
8
|
+
# inside a {@code ConfigIncluder} implementation, and is not intended for apps
|
9
|
+
# to implement.
|
10
|
+
#
|
11
|
+
# <p>
|
12
|
+
# <em>Do not implement this interface</em>; it should only be implemented by
|
13
|
+
# the config library. Arbitrary implementations will not work because the
|
14
|
+
# library internals assume a specific concrete implementation. Also, this
|
15
|
+
# interface is likely to grow new methods over time, so third-party
|
16
|
+
# implementations will break.
|
17
|
+
#
|
18
|
+
module Hocon::ConfigIncludeContext
|
19
|
+
#
|
20
|
+
# Tries to find a name relative to whatever is doing the including, for
|
21
|
+
# example in the same directory as the file doing the including. Returns
|
22
|
+
# null if it can't meaningfully create a relative name. The returned
|
23
|
+
# parseable may not exist; this function is not required to do any IO, just
|
24
|
+
# compute what the name would be.
|
25
|
+
#
|
26
|
+
# The passed-in filename has to be a complete name (with extension), not
|
27
|
+
# just a basename. (Include statements in config files are allowed to give
|
28
|
+
# just a basename.)
|
29
|
+
#
|
30
|
+
# @param filename
|
31
|
+
# the name to make relative to the resource doing the including
|
32
|
+
# @return parseable item relative to the resource doing the including, or
|
33
|
+
# null
|
34
|
+
#
|
35
|
+
def relative_to(filename)
|
36
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigIncludeContext` must implement `relative_to` (#{self.class})"
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Parse options to use (if you use another method to get a
|
41
|
+
# {@link ConfigParseable} then use {@link ConfigParseable#options()}
|
42
|
+
# instead though).
|
43
|
+
#
|
44
|
+
# @return the parse options
|
45
|
+
#
|
46
|
+
def parse_options
|
47
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigIncludeContext` must implement `parse_options` (#{self.class})"
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'hocon'
|
4
|
+
require 'hocon/config_error'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Implement this <em>in addition to</em> {@link ConfigIncluder} if you want to
|
8
|
+
# support inclusion of files with the {@code include file("filename")} syntax.
|
9
|
+
# If you do not implement this but do implement {@link ConfigIncluder},
|
10
|
+
# attempts to load files will use the default includer.
|
11
|
+
#
|
12
|
+
module Hocon::ConfigIncluderFile
|
13
|
+
#
|
14
|
+
# Parses another item to be included. The returned object typically would
|
15
|
+
# not have substitutions resolved. You can throw a ConfigException here to
|
16
|
+
# abort parsing, or return an empty object, but may not return null.
|
17
|
+
#
|
18
|
+
# @param context
|
19
|
+
# some info about the include context
|
20
|
+
# @param what
|
21
|
+
# the include statement's argument
|
22
|
+
# @return a non-null ConfigObject
|
23
|
+
#
|
24
|
+
def include_file(context, what)
|
25
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigIncluderFile` must implement `include_file` (#{self.class})"
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'hocon'
|
4
|
+
require 'hocon/config_value'
|
5
|
+
require 'hocon/config_error'
|
6
|
+
|
7
|
+
#
|
8
|
+
# Subtype of {@link ConfigValue} representing a list value, as in JSON's
|
9
|
+
# {@code [1,2,3]} syntax.
|
10
|
+
#
|
11
|
+
# <p>
|
12
|
+
# {@code ConfigList} implements {@code java.util.List<ConfigValue>} so you can
|
13
|
+
# use it like a regular Java list. Or call {@link #unwrapped()} to unwrap the
|
14
|
+
# list elements into plain Java values.
|
15
|
+
#
|
16
|
+
# <p>
|
17
|
+
# Like all {@link ConfigValue} subtypes, {@code ConfigList} is immutable. This
|
18
|
+
# makes it threadsafe and you never have to create "defensive copies." The
|
19
|
+
# mutator methods from {@link java.util.List} all throw
|
20
|
+
# {@link java.lang.UnsupportedOperationException}.
|
21
|
+
#
|
22
|
+
# <p>
|
23
|
+
# The {@link ConfigValue#valueType} method on a list returns
|
24
|
+
# {@link ConfigValueType#LIST}.
|
25
|
+
#
|
26
|
+
# <p>
|
27
|
+
# <em>Do not implement {@code ConfigList}</em>; it should only be implemented
|
28
|
+
# by the config library. Arbitrary implementations will not work because the
|
29
|
+
# library internals assume a specific concrete implementation. Also, this
|
30
|
+
# interface is likely to grow new methods over time, so third-party
|
31
|
+
# implementations will break.
|
32
|
+
#
|
33
|
+
#
|
34
|
+
module Hocon::ConfigList
|
35
|
+
include Hocon::ConfigValue
|
36
|
+
|
37
|
+
#
|
38
|
+
# Recursively unwraps the list, returning a list of plain Java values such
|
39
|
+
# as Integer or String or whatever is in the list.
|
40
|
+
#
|
41
|
+
def unwrapped
|
42
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigValue should provide their own implementation of `unwrapped` (#{self.class})"
|
43
|
+
end
|
44
|
+
|
45
|
+
def with_origin(origin)
|
46
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigValue should provide their own implementation of `with_origin` (#{self.class})"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'hocon'
|
4
|
+
require 'hocon/config_error'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Marker for types whose instances can be merged, that is {@link Config} and
|
8
|
+
# {@link ConfigValue}. Instances of {@code Config} and {@code ConfigValue} can
|
9
|
+
# be combined into a single new instance using the
|
10
|
+
# {@link ConfigMergeable#withFallback withFallback()} method.
|
11
|
+
#
|
12
|
+
# <p>
|
13
|
+
# <em>Do not implement this interface</em>; it should only be implemented by
|
14
|
+
# the config library. Arbitrary implementations will not work because the
|
15
|
+
# library internals assume a specific concrete implementation. Also, this
|
16
|
+
# interface is likely to grow new methods over time, so third-party
|
17
|
+
# implementations will break.
|
18
|
+
#
|
19
|
+
module Hocon::ConfigMergeable
|
20
|
+
#
|
21
|
+
# Returns a new value computed by merging this value with another, with
|
22
|
+
# keys in this value "winning" over the other one.
|
23
|
+
#
|
24
|
+
# <p>
|
25
|
+
# This associative operation may be used to combine configurations from
|
26
|
+
# multiple sources (such as multiple configuration files).
|
27
|
+
#
|
28
|
+
# <p>
|
29
|
+
# The semantics of merging are described in the <a
|
30
|
+
# href="https://github.com/typesafehub/config/blob/master/HOCON.md">spec
|
31
|
+
# for HOCON</a>. Merging typically occurs when either the same object is
|
32
|
+
# created twice in the same file, or two config files are both loaded. For
|
33
|
+
# example:
|
34
|
+
#
|
35
|
+
# <pre>
|
36
|
+
# foo = { a: 42 }
|
37
|
+
# foo = { b: 43 }
|
38
|
+
# </pre>
|
39
|
+
#
|
40
|
+
# Here, the two objects are merged as if you had written:
|
41
|
+
#
|
42
|
+
# <pre>
|
43
|
+
# foo = { a: 42, b: 43 }
|
44
|
+
# </pre>
|
45
|
+
#
|
46
|
+
# <p>
|
47
|
+
# Only {@link ConfigObject} and {@link Config} instances do anything in
|
48
|
+
# this method (they need to merge the fallback keys into themselves). All
|
49
|
+
# other values just return the original value, since they automatically
|
50
|
+
# override any fallback. This means that objects do not merge "across"
|
51
|
+
# non-objects; if you write
|
52
|
+
# <code>object.withFallback(nonObject).withFallback(otherObject)</code>,
|
53
|
+
# then <code>otherObject</code> will simply be ignored. This is an
|
54
|
+
# intentional part of how merging works, because non-objects such as
|
55
|
+
# strings and integers replace (rather than merging with) any prior value:
|
56
|
+
#
|
57
|
+
# <pre>
|
58
|
+
# foo = { a: 42 }
|
59
|
+
# foo = 10
|
60
|
+
# </pre>
|
61
|
+
#
|
62
|
+
# Here, the number 10 "wins" and the value of <code>foo</code> would be
|
63
|
+
# simply 10. Again, for details see the spec.
|
64
|
+
#
|
65
|
+
# @param other
|
66
|
+
# an object whose keys should be used as fallbacks, if the keys
|
67
|
+
# are not present in this one
|
68
|
+
# @return a new object (or the original one, if the fallback doesn't get
|
69
|
+
# used)
|
70
|
+
#
|
71
|
+
def with_fallback(other)
|
72
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigMergeable` must implement `with_fallback` (#{self.class})"
|
73
|
+
end
|
74
|
+
end
|
data/lib/hocon/config_object.rb
CHANGED
@@ -1,4 +1,147 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'hocon'
|
4
|
+
require 'hocon/config_value'
|
2
5
|
|
6
|
+
#
|
7
|
+
# Subtype of {@link ConfigValue} representing an object (AKA dictionary or map)
|
8
|
+
# value, as in JSON's curly brace <code>{ "a" : 42 }</code> syntax.
|
9
|
+
#
|
10
|
+
# <p>
|
11
|
+
# An object may also be viewed as a {@link Config} by calling
|
12
|
+
# {@link ConfigObject#toConfig()}.
|
13
|
+
#
|
14
|
+
# <p>
|
15
|
+
# {@code ConfigObject} implements {@code java.util.Map<String, ConfigValue>} so
|
16
|
+
# you can use it like a regular Java map. Or call {@link #unwrapped()} to
|
17
|
+
# unwrap the map to a map with plain Java values rather than
|
18
|
+
# {@code ConfigValue}.
|
19
|
+
#
|
20
|
+
# <p>
|
21
|
+
# Like all {@link ConfigValue} subtypes, {@code ConfigObject} is immutable.
|
22
|
+
# This makes it threadsafe and you never have to create "defensive copies." The
|
23
|
+
# mutator methods from {@link java.util.Map} all throw
|
24
|
+
# {@link java.lang.UnsupportedOperationException}.
|
25
|
+
#
|
26
|
+
# <p>
|
27
|
+
# The {@link ConfigValue#valueType} method on an object returns
|
28
|
+
# {@link ConfigValueType#OBJECT}.
|
29
|
+
#
|
30
|
+
# <p>
|
31
|
+
# In most cases you want to use the {@link Config} interface rather than this
|
32
|
+
# one. Call {@link #toConfig()} to convert a {@code ConfigObject} to a
|
33
|
+
# {@code Config}.
|
34
|
+
#
|
35
|
+
# <p>
|
36
|
+
# The API for a {@code ConfigObject} is in terms of keys, while the API for a
|
37
|
+
# {@link Config} is in terms of path expressions. Conceptually,
|
38
|
+
# {@code ConfigObject} is a tree of maps from keys to values, while a
|
39
|
+
# {@code Config} is a one-level map from paths to values.
|
40
|
+
#
|
41
|
+
# <p>
|
42
|
+
# Use {@link ConfigUtil#joinPath} and {@link ConfigUtil#splitPath} to convert
|
43
|
+
# between path expressions and individual path elements (keys).
|
44
|
+
#
|
45
|
+
# <p>
|
46
|
+
# A {@code ConfigObject} may contain null values, which will have
|
47
|
+
# {@link ConfigValue#valueType()} equal to {@link ConfigValueType#NULL}. If
|
48
|
+
# {@link ConfigObject#get(Object)} returns Java's null then the key was not
|
49
|
+
# present in the parsed file (or wherever this value tree came from). If
|
50
|
+
# {@code get("key")} returns a {@link ConfigValue} with type
|
51
|
+
# {@code ConfigValueType#NULL} then the key was set to null explicitly in the
|
52
|
+
# config file.
|
53
|
+
#
|
54
|
+
# <p>
|
55
|
+
# <em>Do not implement interface {@code ConfigObject}</em>; it should only be
|
56
|
+
# implemented by the config library. Arbitrary implementations will not work
|
57
|
+
# because the library internals assume a specific concrete implementation.
|
58
|
+
# Also, this interface is likely to grow new methods over time, so third-party
|
59
|
+
# implementations will break.
|
60
|
+
#
|
3
61
|
module Hocon::ConfigObject
|
4
|
-
|
62
|
+
include Hocon::ConfigValue
|
63
|
+
|
64
|
+
#
|
65
|
+
# Converts this object to a {@link Config} instance, enabling you to use
|
66
|
+
# path expressions to find values in the object. This is a constant-time
|
67
|
+
# operation (it is not proportional to the size of the object).
|
68
|
+
#
|
69
|
+
# @return a {@link Config} with this object as its root
|
70
|
+
#
|
71
|
+
def to_config
|
72
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigObject should provide their own implementation of `to_config` (#{self.class})"
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Recursively unwraps the object, returning a map from String to whatever
|
77
|
+
# plain Java values are unwrapped from the object's values.
|
78
|
+
#
|
79
|
+
# @return a {@link java.util.Map} containing plain Java objects
|
80
|
+
#
|
81
|
+
def unwrapped
|
82
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigObject should provide their own implementation of `unwrapped` (#{self.class})"
|
83
|
+
end
|
84
|
+
|
85
|
+
def with_fallback(other)
|
86
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigObject should provide their own implementation of `with_fallback` (#{self.class})"
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Gets a {@link ConfigValue} at the given key, or returns null if there is
|
91
|
+
# no value. The returned {@link ConfigValue} may have
|
92
|
+
# {@link ConfigValueType#NULL} or any other type, and the passed-in key
|
93
|
+
# must be a key in this object (rather than a path expression).
|
94
|
+
#
|
95
|
+
# @param key
|
96
|
+
# key to look up
|
97
|
+
#
|
98
|
+
# @return the value at the key or null if none
|
99
|
+
#
|
100
|
+
def get(key)
|
101
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigObject should provide their own implementation of `get` (#{self.class})"
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# Clone the object with only the given key (and its children) retained; all
|
106
|
+
# sibling keys are removed.
|
107
|
+
#
|
108
|
+
# @param key
|
109
|
+
# key to keep
|
110
|
+
# @return a copy of the object minus all keys except the one specified
|
111
|
+
#
|
112
|
+
def with_only_key(key)
|
113
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigObject should provide their own implementation of `with_only_key` (#{self.class})"
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Clone the object with the given key removed.
|
118
|
+
#
|
119
|
+
# @param key
|
120
|
+
# key to remove
|
121
|
+
# @return a copy of the object minus the specified key
|
122
|
+
#
|
123
|
+
def without_key(key)
|
124
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigObject should provide their own implementation of `without_key` (#{self.class})"
|
125
|
+
end
|
126
|
+
|
127
|
+
#
|
128
|
+
# Returns a {@code ConfigObject} based on this one, but with the given key
|
129
|
+
# set to the given value. Does not modify this instance (since it's
|
130
|
+
# immutable). If the key already has a value, that value is replaced. To
|
131
|
+
# remove a value, use {@link ConfigObject#withoutKey(String)}.
|
132
|
+
#
|
133
|
+
# @param key
|
134
|
+
# key to add
|
135
|
+
# @param value
|
136
|
+
# value at the new key
|
137
|
+
# @return the new instance with the new map entry
|
138
|
+
#
|
139
|
+
def with_value(key, value)
|
140
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigObject should provide their own implementation of `with_value` (#{self.class})"
|
141
|
+
end
|
142
|
+
|
143
|
+
def with_origin(origin)
|
144
|
+
raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigObject should provide their own implementation of `with_origin` (#{self.class})"
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|