class Hocon::Impl::ConfigNodeRoot

Public Class Methods

new(children, origin) click to toggle source
Calls superclass method Hocon::Impl::ConfigNodeComplexValue.new
# File lib/hocon/impl/config_node_root.rb, line 9
def initialize(children, origin)
  super(children)
  @origin = origin
end

Public Instance Methods

has_value(desired_path) click to toggle source
# File lib/hocon/impl/config_node_root.rb, line 46
def has_value(desired_path)
  path = Hocon::Impl::PathParser.parse_path(desired_path)
  @children.each do |node|
    if node.is_a?(Hocon::Impl::ConfigNodeComplexValue)
      if node.is_a?(Hocon::Impl::ConfigNodeArray)
        raise Hocon::ConfigError::ConfigBugOrBrokenError, "The ConfigDocument had an array at the root level, and values cannot be modified inside an array."
      elsif node.is_a?(Hocon::Impl::ConfigNodeObject)
        return node.has_value(path)
      end
    end
  end
  raise Hocon::ConfigError::ConfigBugOrBrokenError, "ConfigNodeRoot did not contain a value"
end
new_node(nodes) click to toggle source
# File lib/hocon/impl/config_node_root.rb, line 14
def new_node(nodes)
  raise Hocon::ConfigError::ConfigBugOrBrokenError, "Tried to indent the root object"
end
set_value(desired_path, value, flavor) click to toggle source
# File lib/hocon/impl/config_node_root.rb, line 27
def set_value(desired_path, value, flavor)
  children_copy = @children.clone
  children_copy.each_with_index do |node, index|
    if node.is_a?(Hocon::Impl::ConfigNodeComplexValue)
      if node.is_a?(Hocon::Impl::ConfigNodeArray)
        raise Hocon::ConfigError::ConfigBugOrBrokenError, "The ConfigDocument had an array at the root level, and values cannot be modified inside an array."
      elsif node.is_a?(Hocon::Impl::ConfigNodeObject)
        if value.nil?
          children_copy[index] = node.remove_value_on_path(desired_path, flavor)
        else
          children_copy[index] = node.set_value_on_path(desired_path, value, flavor)
        end
        return self.class.new(children_copy, @origin)
      end
    end
  end
  raise Hocon::ConfigError::ConfigBugOrBrokenError, "ConfigNodeRoot did not contain a value"
end
value() click to toggle source
# File lib/hocon/impl/config_node_root.rb, line 18
def value
  @children.each do |node|
    if node.is_a?(Hocon::Impl::ConfigNodeComplexValue)
      return node
    end
  end
  raise Hocon::ConfigError::ConfigBugOrBrokenError, "ConfigNodeRoot did not contain a value"
end