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.



9
10
11
12
# File 'lib/hocon/impl/path_builder.rb', line 9

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

Instance Method Details

#append_key(key) ⇒ Object



20
21
22
23
# File 'lib/hocon/impl/path_builder.rb', line 20

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

#append_path(path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hocon/impl/path_builder.rb', line 25

def append_path(path)
  check_can_append

  first = path.first
  remainder = path.remainder

  loop do
    @keys.push(first)

    if !remainder.nil?
      first = remainder.first
      remainder = remainder.remainder
    else
      break
    end
  end
end

#check_can_appendObject



14
15
16
17
18
# File 'lib/hocon/impl/path_builder.rb', line 14

def check_can_append
  if @result
    raise Hocon::ConfigError::ConfigBugOrBrokenError, "Adding to PathBuilder after getting result"
  end
end

#resultObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hocon/impl/path_builder.rb', line 43

def result
  # note: if keys is empty, we want to return nil, 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