Class: Hocon::Impl::ConfigReference

Inherits:
Object
  • Object
show all
Includes:
AbstractConfigValue, Unmergeable
Defined in:
lib/hocon/impl/config_reference.rb

Constant Summary collapse

NotPossibleToResolve =
Hocon::Impl::AbstractConfigValue::NotPossibleToResolve
UnresolvedSubstitutionError =
Hocon::ConfigError::UnresolvedSubstitutionError

Constants included from AbstractConfigValue

AbstractConfigValue::ConfigBugOrBrokenError, AbstractConfigValue::ConfigImplUtil, AbstractConfigValue::ResolveStatus

Instance Attribute Summary collapse

Attributes included from AbstractConfigValue

#origin

Instance Method Summary collapse

Methods included from AbstractConfigValue

#at_key, #at_key_with_origin, #at_path, #at_path_with_origin, #construct_delayed_merge, #delay_merge, has_descendant_in_list?, indent, #inspect, #merged_stack_with_non_object, #merged_stack_with_object, #merged_stack_with_the_unmergeable, #merged_with_non_object, #merged_with_object, #merged_with_the_unmergeable, #render, #render_to_sb, replace_child_in_list, #require_not_ignoring_fallbacks, #to_fallback_value, #to_s, #transform_to_string, #with_fallback, #with_fallbacks_ignored, #with_origin

Methods included from ConfigValue

#at_key, #at_path, #origin, #render, #with_fallback, #with_origin

Methods included from ConfigMergeable

#with_fallback

Constructor Details

#initialize(origin, expr, prefix_length = 0) ⇒ ConfigReference

Returns a new instance of ConfigReference.



21
22
23
24
25
# File 'lib/hocon/impl/config_reference.rb', line 21

def initialize(origin, expr, prefix_length = 0)
  super(origin)
  @expr = expr
  @prefix_length = prefix_length
end

Instance Attribute Details

#exprObject (readonly)

Returns the value of attribute expr.



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

def expr
  @expr
end

#prefix_lengthObject (readonly)

Returns the value of attribute prefix_length.



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

def prefix_length
  @prefix_length
end

Instance Method Details

#==(other) ⇒ Object



118
119
120
121
122
123
# File 'lib/hocon/impl/config_reference.rb', line 118

def ==(other)
  # note that "origin" is deliberately NOT part of equality
  if other.is_a? Hocon::Impl::ConfigReference
    can_equal(other) && @expr == other.expr
  end
end

#can_equal(other) ⇒ Object



114
115
116
# File 'lib/hocon/impl/config_reference.rb', line 114

def can_equal(other)
  other.is_a? Hocon::Impl::ConfigReference
end

#expressionObject



134
135
136
# File 'lib/hocon/impl/config_reference.rb', line 134

def expression
  @expr
end

#hashObject



125
126
127
128
# File 'lib/hocon/impl/config_reference.rb', line 125

def hash
  # note that "origin" is deliberately NOT part of equality
  @expr.hash
end

#ignores_fallbacks?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/hocon/impl/config_reference.rb', line 100

def ignores_fallbacks?
  false
end

#new_copy(new_origin) ⇒ Object



96
97
98
# File 'lib/hocon/impl/config_reference.rb', line 96

def new_copy(new_origin)
  Hocon::Impl::ConfigReference.new(new_origin, @expr, @prefix_length)
end

#relativized(prefix) ⇒ Object



108
109
110
111
112
# File 'lib/hocon/impl/config_reference.rb', line 108

def relativized(prefix)
  new_expr = @expr.change_path(@expr.path.prepend(prefix))

  Hocon::Impl::ConfigReference.new(origin, new_expr, @prefix_length + prefix.length)
end

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



130
131
132
# File 'lib/hocon/impl/config_reference.rb', line 130

def render_value_to_sb(sb, indent, at_root, options)
  sb << @expr.to_s
end

#resolve_statusObject



104
105
106
# File 'lib/hocon/impl/config_reference.rb', line 104

def resolve_status
  Hocon::Impl::ResolveStatus::UNRESOLVED
end

#resolve_substitutions(context, source) ⇒ Object

ConfigReference should be a firewall against NotPossibleToResolve going further up the stack; it should convert everything to ConfigException. This way it ‘s impossible for NotPossibleToResolve to “escape” since any failure to resolve has to start with a ConfigReference.



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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/hocon/impl/config_reference.rb', line 35

def resolve_substitutions(context, source)
  new_context = context.add_cycle_marker(self)
  begin
    result_with_path = source.lookup_subst(new_context, @expr, @prefix_length)
    new_context = result_with_path.result.context

    if result_with_path.result.value != nil
      if Hocon::Impl::ConfigImpl.trace_substitution_enabled
        Hocon::Impl::ConfigImpl.trace(
            "recursively resolving #{result_with_path} which was the resolution of #{expr} against #{source}",
            context.depth)
      end

      recursive_resolve_source = Hocon::Impl::ResolveSource.new(
          result_with_path.path_from_root.last, result_with_path.path_from_root)

      if Hocon::Impl::ConfigImpl.trace_substitution_enabled
        Hocon::Impl::ConfigImpl.trace("will recursively resolve against #{recursive_resolve_source}", context.depth)
      end

      result = new_context.resolve(result_with_path.result.value,
                                   recursive_resolve_source)
      v = result.value
      new_context = result.context
    else
      v = nil
    end
  rescue NotPossibleToResolve => e
    if Hocon::Impl::ConfigImpl.trace_substitution_enabled
      Hocon::Impl::ConfigImpl.trace(
          "not possible to resolve #{expr}, cycle involved: #{e.trace_string}", new_context.depth)
    end
    if @expr.optional
      v = nil
    else
      raise UnresolvedSubstitutionError.new(
                origin,
                "#{@expr} was part of a cycle of substitutions involving #{e.trace_string}", e)
    end
  end

  if v == nil && !@expr.optional
    if new_context.options.allow_unresolved
      ResolveResult.make(new_context.remove_cycle_marker(self), self)
    else
      raise UnresolvedSubstitutionError.new(origin, @expr.to_s)
    end
  else
    Hocon::Impl::ResolveResult.make(new_context.remove_cycle_marker(self), v)
  end

end

#unmerged_valuesObject



27
28
29
# File 'lib/hocon/impl/config_reference.rb', line 27

def unmerged_values
  [self]
end

#unwrappedObject



92
93
94
# File 'lib/hocon/impl/config_reference.rb', line 92

def unwrapped
  raise not_resolved
end

#value_typeObject



88
89
90
# File 'lib/hocon/impl/config_reference.rb', line 88

def value_type
  raise not_resolved
end