Class: Hocon::ConfigValueFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/hocon/config_value_factory.rb

Constant Summary collapse

ConfigImpl =
Hocon::Impl::ConfigImpl

Class Method Summary collapse

Class Method Details

.from_any_ref(object, origin_description = nil) ⇒ Object

Creates a ConfigValue from a plain value, which may be a Boolean, Number, String, Hash, or nil. A Hash must be a Hash from String to more values that can be supplied to from_any_ref(). A Hash will become a ConfigObject and an Array will become a ConfigList.

<p> In a Hash passed to from_any_ref(), the map’s keys are plain keys, not path expressions. So if your Hash has a key “foo.bar” then you will get one object with a key called “foo.bar”, rather than an object with a key “foo” containing another object with a key “bar”.

<p> The origin_description will be used to set the origin() field on the ConfigValue. It should normally be the name of the file the values came from, or something short describing the value such as “default settings”. The origin_description is prefixed to error messages so users can tell where problematic values are coming from.

<p> Supplying the result of ConfigValue.unwrapped() to this function is guaranteed to work and should give you back a ConfigValue that matches the one you unwrapped. The re-wrapped ConfigValue will lose some information that was present in the original such as its origin, but it will have matching values.

<p> If you pass in a ConfigValue to this function, it will be returned unmodified. (The origin_description will be ignored in this case.)

<p> This function throws if you supply a value that cannot be converted to a ConfigValue, but supplying such a value is a bug in your program, so you should never handle the exception. Just fix your program (or report a bug against this library).

Parameters:

  • object

    object to convert to ConfigValue

  • origin_description (defaults to: nil)

    name of origin file or brief description of what the value is

Returns:

  • a new value



57
58
59
# File 'lib/hocon/config_value_factory.rb', line 57

def self.from_any_ref(object, origin_description = nil)
  ConfigImpl.from_any_ref(object, origin_description)
end

.from_map(values, origin_description = nil) ⇒ Object

See the #from_any_ref(Object,String) documentation for details

<p> See also ConfigFactory#parse_map(Map) which interprets the keys in the map as path expressions.

Parameters:

  • values

    map from keys to plain ruby values

Returns:

  • a new ConfigObject



71
72
73
# File 'lib/hocon/config_value_factory.rb', line 71

def self.from_map(values, origin_description = nil)
  ConfigImpl.from_any_ref(values, origin_description)
end