Class: Hocon::Impl::ConfigNodeRoot
- Inherits:
-
Object
- Object
- Hocon::Impl::ConfigNodeRoot
- Includes:
- ConfigNodeComplexValue
- Defined in:
- lib/hocon/impl/config_node_root.rb
Instance Attribute Summary
Attributes included from ConfigNodeComplexValue
Instance Method Summary collapse
- #has_value(desired_path) ⇒ Object
-
#initialize(children, origin) ⇒ ConfigNodeRoot
constructor
A new instance of ConfigNodeRoot.
- #new_node(nodes) ⇒ Object
- #set_value(desired_path, value, flavor) ⇒ Object
- #value ⇒ Object
Methods included from ConfigNodeComplexValue
Methods included from AbstractConfigNode
Methods included from Parser::ConfigNode
Constructor Details
#initialize(children, origin) ⇒ ConfigNodeRoot
Returns a new instance of ConfigNodeRoot.
10 11 12 13 |
# File 'lib/hocon/impl/config_node_root.rb', line 10 def initialize(children, origin) super(children) @origin = origin end |
Instance Method Details
#has_value(desired_path) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/hocon/impl/config_node_root.rb', line 47 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) ⇒ Object
15 16 17 |
# File 'lib/hocon/impl/config_node_root.rb', line 15 def new_node(nodes) raise Hocon::ConfigError::ConfigBugOrBrokenError, "Tried to indent the root object" end |
#set_value(desired_path, value, flavor) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hocon/impl/config_node_root.rb', line 28 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 ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/hocon/impl/config_node_root.rb', line 19 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 |