Class: Hocon::Impl::SimpleConfigList

Inherits:
AbstractConfigValue show all
Defined in:
lib/hocon/impl/simple_config_list.rb

Constant Summary collapse

ResolveStatus =
Hocon::Impl::ResolveStatus

Constants inherited from AbstractConfigValue

AbstractConfigValue::ConfigImplUtil

Instance Attribute Summary

Attributes inherited from AbstractConfigValue

#origin

Instance Method Summary collapse

Methods inherited from AbstractConfigValue

#ignores_fallbacks?, #indent, #render, #render_to_sb, #require_not_ignoring_fallbacks, #resolve_status, #to_s, #with_fallback, #with_origin

Constructor Details

#initialize(origin, value, status = ResolveStatus.from_values(value)) ⇒ SimpleConfigList

Returns a new instance of SimpleConfigList.



8
9
10
11
12
13
14
15
16
17
# File 'lib/hocon/impl/simple_config_list.rb', line 8

def initialize(origin, value, status = ResolveStatus.from_values(value))
  super(origin)
  @value = value
  @resolved = (status == ResolveStatus::RESOLVED)

  # kind of an expensive debug check (makes this constructor pointless)
  if status != ResolveStatus.from_values(value)
    raise ConfigBugError, "SimpleConfigList created with wrong resolve status: #{self}"
  end
end

Instance Method Details

#new_copy(origin) ⇒ Object



71
72
73
# File 'lib/hocon/impl/simple_config_list.rb', line 71

def new_copy(origin)
  Hocon::Impl::SimpleConfigList.new(origin, @value)
end

#render_value_to_sb(sb, indent_size, at_root, options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/hocon/impl/simple_config_list.rb', line 27

def render_value_to_sb(sb, indent_size, at_root, options)
  if @value.empty?
    sb << "[]"
  else
    sb << "["
    if options.formatted?
      sb << "\n"
    end
    @value.each do |v|
      if options.origin_comments?
        indent(sb, indent_size + 1, options)
        sb << "# "
        sb << v.origin.description
        sb << "\n"
      end
      if options.comments?
        v.origin.comments.each do |comment|
          sb << "# "
          sb << comment
          sb << "\n"
        end
      end
      indent(sb, indent_size + 1, options)

      v.render_value_to_sb(sb, indent_size + 1, at_root, options)
      sb << ","
      if options.formatted?
        sb << "\n"
      end
    end

    # couldn't figure out a better way to chop characters off of the end of
    # the StringIO.  This relies on making sure that, prior to returning the
    # final string, we take a substring that ends at sb.pos.
    sb.pos = sb.pos - 1 # chop or newline
    if options.formatted?
      sb.pos = sb.pos - 1 # also chop comma
      sb << "\n"
      indent(sb, indent_size, options)
    end
    sb << "]"
  end
end

#unwrappedObject



23
24
25
# File 'lib/hocon/impl/simple_config_list.rb', line 23

def unwrapped
  @value.map { |v| v.unwrapped }
end

#value_typeObject



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

def value_type
  Hocon::ConfigValueType::LIST
end