Module: Hocon::Parser::ConfigDocument

Included in:
Impl::SimpleConfigDocument
Defined in:
lib/hocon/parser/config_document.rb

Overview

Represents an individual HOCON or JSON file, preserving all formatting and syntax details. This can be used to replace individual values and exactly render the original text of the input.

<p> Because this object is immutable, it is safe to use from multiple threads and there’s no need for “defensive copies.”

<p> Do not implement interface ConfigDocument; it should only be implemented by the config library. Arbitrary implementations will not work because the library internals assume a specific concrete implementation.# Also, this interface is likely to grow new methods over time, so third-party implementations will break.

Instance Method Summary collapse

Instance Method Details

#has_value?(path) ⇒ Boolean

Returns a boolean indicating whether or not a ConfigDocument has a value at the desired path.



80
81
82
# File 'lib/hocon/parser/config_document.rb', line 80

def has_value?(path)
  raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigDocument should override `render` (#{self.class})"
end

#remove_value(path) ⇒ Object

Returns a new ConfigDocument that is a copy of the current ConfigDocument, but with the value at the desired path removed. If the desired path does not exist in the document, a copy of the current document will be returned. If there is an array at the root, an exception will be thrown.



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

def remove_value(path)
  raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigDocument should override `render` (#{self.class})"
end

#renderObject

The original text of the input, modified if necessary with any replaced or added values.



89
90
91
# File 'lib/hocon/parser/config_document.rb', line 89

def render
  raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigDocument should override `render` (#{self.class})"
end

#set_config_value(path, new_value) ⇒ Object

Returns a new ConfigDocument that is a copy of the current ConfigDocument, but with the desired value set at the desired path as with #setValue(String, String), but takes a ConfigValue instead of a string.



58
59
60
# File 'lib/hocon/parser/config_document.rb', line 58

def set_config_value(path, new_value)
  raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigDocument should override `render` (#{self.class})"
end

#set_value(path, new_value) ⇒ Object

Returns a new ConfigDocument that is a copy of the current ConfigDocument, but with the desired value set at the desired path. If the path exists, it will remove all duplicates before the final occurrence of the path, and replace the value at the final occurrence of the path. If the path does not exist, it will be added. If the document has an array as the root value, an exception will be thrown.



43
44
45
# File 'lib/hocon/parser/config_document.rb', line 43

def set_value(path, new_value)
  raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of ConfigDocument should override `render` (#{self.class})"
end