Class: Hocon::Impl::PathBuilder

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

Constant Summary collapse

Path =
Hocon::Impl::Path

Instance Method Summary collapse

Constructor Details

#initializePathBuilder

Returns a new instance of PathBuilder.



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

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

Instance Method Details

#append_key(key) ⇒ Object



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

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

#check_can_appendObject



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

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

#resultObject



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

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 = Path.new(key, remainder)
    end
    @result = remainder
  end
  @result
end