Class: Hocon::Impl::PathBuilder

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

Instance Method Summary collapse

Constructor Details

#initializePathBuilder

Returns a new instance of PathBuilder.



6
7
8
9
# File 'lib/hocon/impl/path_builder.rb', line 6

def initialize
  @keys = []
  @result = nil
end

Instance Method Details

#append_key(key) ⇒ Object



17
18
19
20
# File 'lib/hocon/impl/path_builder.rb', line 17

def append_key(key)
  check_can_append
  @keys.push(key)
end

#check_can_appendObject



11
12
13
14
15
# File 'lib/hocon/impl/path_builder.rb', line 11

def check_can_append
  if @result
    raise ConfigBugError, "Adding to PathBuilder after getting result"
  end
end

#resultObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hocon/impl/path_builder.rb', line 22

def result
  # note: if keys is empty, we want to return null, which is a valid
  # empty path
  if @result.nil?
    remainder = nil
    while !@keys.empty?
      key = @keys.pop
      remainder = Hocon::Impl::Path.new(key, remainder)
    end
    @result = remainder
  end
  @result
end