Method: Config#resolve

Defined in:
lib/hocon/config.rb

#resolve(options) ⇒ Object

Returns a replacement config with all substitutions (the ${foo.bar} syntax, see <a href=“github.com/typesafehub/config/blob/master/HOCON.md”>the spec</a>) resolved. Substitutions are looked up using this Config as the root object, that is, a substitution ${foo.bar} will be replaced with the result of getValue("foo.bar").

<p> This method uses ConfigResolveOptions#defaults(), there is another variant Config#resolve(ConfigResolveOptions) which lets you specify non-default options.

<p> A given Config must be resolved before using it to retrieve config values, but ideally should be resolved one time for your entire stack of fallbacks (see Config#withFallback). Otherwise, some substitutions that could have resolved with all fallbacks available may not resolve, which will be potentially confusing for your application’s users.

<p> resolve() should be invoked on root config objects, rather than on a subtree (a subtree is the result of something like config.getConfig("foo")). The problem with resolve() on a subtree is that substitutions are relative to the root of the config and the subtree will have no way to get values from the root. For example, if you did config.getConfig("foo").resolve() on the below config file, it would not work:

<pre>

common-value = 10
foo {
   whatever = ${common-value}
}

</pre>

<p> Many methods on ConfigFactory such as ConfigFactory#load() automatically resolve the loaded Config on the loaded stack of config files.

<p> Resolving an already-resolved config is a harmless no-op, but again, it is best to resolve an entire stack of fallbacks (such as all your config files combined) rather than resolving each one individually.

Returns:

  • an immutable object with substitutions resolved

Raises:



241
242
243
# File 'lib/hocon/config.rb', line 241

def resolve(options)
  raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `Config` must implement `resolve` (#{self.class})"
end