class Hocon::Impl::ConfigReference

Constants

NotPossibleToResolve

This exception means that a value is inherently not resolveable, at the moment the only known cause is a cycle of substitutions. This is a checked exception since it's internal to the library and we want to be sure we handle it before passing it out to public API. This is only supposed to be thrown by the target of a cyclic reference and it's supposed to be caught by the ConfigReference looking up that reference, so it should be impossible for an outermost resolve() to throw this.

Contrast with ConfigException.NotResolved which just means nobody called resolve().

UnresolvedSubstitutionError

Attributes

expr[R]
prefix_length[R]

Public Class Methods

new(origin, expr, prefix_length = 0) click to toggle source
Calls superclass method Hocon::Impl::AbstractConfigValue.new
# File lib/hocon/impl/config_reference.rb, line 17
def initialize(origin, expr, prefix_length = 0)
  super(origin)
  @expr = expr
  @prefix_length = prefix_length
end

Public Instance Methods

==(other) click to toggle source
# File lib/hocon/impl/config_reference.rb, line 114
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) click to toggle source
# File lib/hocon/impl/config_reference.rb, line 110
def can_equal(other)
  other.is_a? Hocon::Impl::ConfigReference
end
expression() click to toggle source
# File lib/hocon/impl/config_reference.rb, line 130
def expression
  @expr
end
hash() click to toggle source
# File lib/hocon/impl/config_reference.rb, line 121
def hash
  # note that "origin" is deliberately NOT part of equality
  @expr.hash
end
ignores_fallbacks?() click to toggle source
# File lib/hocon/impl/config_reference.rb, line 96
def ignores_fallbacks?
  false
end
new_copy(new_origin) click to toggle source
# File lib/hocon/impl/config_reference.rb, line 92
def new_copy(new_origin)
  Hocon::Impl::ConfigReference.new(new_origin, @expr, @prefix_length)
end
relativized(prefix) click to toggle source
# File lib/hocon/impl/config_reference.rb, line 104
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) click to toggle source
# File lib/hocon/impl/config_reference.rb, line 126
def render_value_to_sb(sb, indent, at_root, options)
  sb << @expr.to_s
end
resolve_status() click to toggle source
# File lib/hocon/impl/config_reference.rb, line 100
def resolve_status
  Hocon::Impl::ResolveStatus::UNRESOLVED
end
resolve_substitutions(context, source) click to toggle source

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.

# File lib/hocon/impl/config_reference.rb, line 31
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_values() click to toggle source
# File lib/hocon/impl/config_reference.rb, line 23
def unmerged_values
  [self]
end
unwrapped() click to toggle source
# File lib/hocon/impl/config_reference.rb, line 88
def unwrapped
  raise not_resolved
end
value_type() click to toggle source
# File lib/hocon/impl/config_reference.rb, line 84
def value_type
  raise not_resolved
end

Private Instance Methods

not_resolved() click to toggle source
# File lib/hocon/impl/config_reference.rb, line 136
def not_resolved
  error_message = "need to Config#resolve, see the API docs for Config#resolve; substitution not resolved: #{self}"
  Hocon::ConfigError::ConfigNotResolvedError.new(error_message, nil)
end