Class: Hocon::Impl::SimpleConfigDocument

Inherits:
Object
  • Object
show all
Includes:
Parser::ConfigDocument
Defined in:
lib/hocon/impl/simple_config_document.rb

Instance Method Summary collapse

Constructor Details

#initialize(parsed_node, parse_options) ⇒ SimpleConfigDocument

Returns a new instance of SimpleConfigDocument.



10
11
12
13
# File 'lib/hocon/impl/simple_config_document.rb', line 10

def initialize(parsed_node, parse_options)
  @config_node_tree = parsed_node
  @parse_options = parse_options
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
# File 'lib/hocon/impl/simple_config_document.rb', line 41

def ==(other)
  other.class.ancestors.include?(Hocon::Parser::ConfigDocument) && render == other.render
end

#has_value?(path) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/hocon/impl/simple_config_document.rb', line 33

def has_value?(path)
  @config_node_tree.has_value(path)
end

#hashObject



45
46
47
# File 'lib/hocon/impl/simple_config_document.rb', line 45

def hash
  render.hash
end

#remove_value(path) ⇒ Object



29
30
31
# File 'lib/hocon/impl/simple_config_document.rb', line 29

def remove_value(path)
  self.class.new(@config_node_tree.set_value(path, nil, @parse_options.syntax), @parse_options)
end

#renderObject



37
38
39
# File 'lib/hocon/impl/simple_config_document.rb', line 37

def render
  @config_node_tree.render
end

#set_config_value(path, new_value) ⇒ Object



25
26
27
# File 'lib/hocon/impl/simple_config_document.rb', line 25

def set_config_value(path, new_value)
  set_value(path, new_value.render.strip)
end

#set_value(path, new_value) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/hocon/impl/simple_config_document.rb', line 15

def set_value(path, new_value)
  origin = Hocon::Impl::SimpleConfigOrigin.new_simple("single value parsing")
  reader = StringIO.new(new_value)
  tokens = Hocon::Impl::Tokenizer.tokenize(origin, reader, @parse_options.syntax)
  parsed_value = Hocon::Impl::ConfigDocumentParser.parse_value(tokens, origin, @parse_options)
  reader.close

  self.class.new(@config_node_tree.set_value(path, parsed_value, @parse_options.syntax), @parse_options)
end