class Hocon::Impl::ConfigDelayedMergeObject

This is just like ConfigDelayedMerge except we know statically that it will turn out to be an object.

Attributes

stack[R]

Public Class Methods

new(origin, stack) click to toggle source
Calls superclass method Hocon::Impl::AbstractConfigObject::new
# File lib/hocon/impl/config_delayed_merge_object.rb, line 12
def initialize(origin, stack)
  super(origin)

  @stack = stack

  if stack.empty?
    raise Hocon::ConfigError::ConfigBugOrBrokenError.new("creating empty delayed merge value", nil)
  end

  if !@stack[0].is_a? Hocon::Impl::AbstractConfigObject
    error_message = "created a delayed merge object not guaranteed to be an object"
    raise Hocon::ConfigError::ConfigBugOrBrokenError.new(error_message, nil)
  end

  stack.each do |v|
    if v.is_a?(Hocon::Impl::ConfigDelayedMergeObject) || v.is_a?(Hocon::Impl::ConfigDelayedMergeObject)
      error_message = "placed nested DelayedMerge in a ConfigDelayedMerge, should have consolidated stack"
      raise Hocon::ConfigError::ConfigBugOrBrokenError.new(error_message, nil)
    end
  end
end
not_resolved() click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 151
def self.not_resolved
  error_message = "need to Config#resolve() before using this object, see the API docs for Config#resolve()"
  Hocon::ConfigError::ConfigNotResolvedError.new(error_message, nil)
end
unmergeable?(object) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 192
def self.unmergeable?(object)
  # Ruby note: This is the best way I could find to simulate
  # else if (layer instanceof Unmergeable) in java since we're including
  # the Unmergeable module instead of extending an Unmergeable class
  object.class.included_modules.include?(Hocon::Impl::Unmergeable)
end

Public Instance Methods

==(other) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 133
def ==(other)
  # note that "origin" is deliberately NOT part of equality
  if other.is_a? Hocon::Impl::ConfigDelayedMergeObject
    can_equal(other) && (@stack == other.stack || @stack.equal?(other.stack))
  else
    false
  end
end
[](key) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 160
def [](key)
  raise self.class.not_resolved
end
attempt_peek_with_partial_resolve(key) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 199
def attempt_peek_with_partial_resolve(key)
  # a partial resolve of a ConfigDelayedMergeObject always results in a
  # SimpleConfigObject because all the substitutions in the stack get
  # resolved in order to look up the partial.
  # So we know here that we have not been resolved at all even
  # partially.
  # Given that, all this code is probably gratuitous, since the app code
  # is likely broken. But in general we only throw NotResolved if you try
  # to touch the exact key that isn't resolved, so this is in that
  # spirit.

  # we'll be able to return a key if we have a value that ignores
  # fallbacks, prior to any unmergeable values.
  @stack.each do |layer|
    if layer.is_a?(Hocon::Impl::AbstractConfigObject)
      v = layer.attempt_peek_with_partial_resolve(key)

      if !v.nil?
        if v.ignores_fallbacks?
          # we know we won't need to merge anything in to this
          # value
          return v
        else
          # we can't return this value because we know there are
          # unmergeable values later in the stack that may
          # contain values that need to be merged with this
          # value. we'll throw the exception when we get to those
          # unmergeable values, so continue here.
          next
        end
      elsif self.class.unmergeable?(layer)
        error_message = "should not be reached: unmergeable object returned null value"
        raise Hocon::ConfigError::ConfigBugOrBrokenError.new(error_message, nil)
      else
        # a non-unmergeable AbstractConfigObject that returned null
        # for the key in question is not relevant, we can keep
        # looking for a value.
        next
      end
    elsif self.class.unmergeable?(layer)
      error_message = "Key '#{key}' is not available at '#{origin.description}'" +
          "because value at '#{layer.origin.description}' has not been resolved" +
          " and may turn out to contain or hide '#{key}'. Be sure to Config#resolve()" +
          " before using a config object"
      raise Hocon::ConfigError::ConfigNotResolvedError.new(error_message, nil)
    elsif layer.resolved_status == ResolveStatus::UNRESOLVED
      # if the layer is not an object, and not a substitution or
      # merge,
      # then it's something that's unresolved because it _contains_
      # an unresolved object... i.e. it's an array
      if !layer.is_a?(Hocon::Impl::ConfigList)
        error_message = "Expecting a list here, not #{layer}"
        raise Hocon::ConfigError::ConfigBugOrBrokenError.new(error_message, nil)
      end
      return nil
    else
      # non-object, but resolved, like an integer or something.
      # has no children so the one we're after won't be in it.
      # we would only have this in the stack in case something
      # else "looks back" to it due to a cycle.
      # anyway at this point we know we can't find the key anymore.
      if !layer.ignores_fallbacks?
        error_message = "resolved non-object should ignore fallbacks"
        raise Hocon::ConfigError::ConfigBugOrBrokenError.new(error_message, nil)
      end
      return nil
    end
  end

  # If we get here, then we never found anything unresolved which means
  # the ConfigDelayedMergeObject should not have existed. some
  # invariant was violated.
  error_message = "Delayed merge stack does not contain any unmergeable values"
  raise Hocon::ConfigError::ConfigBugOrBrokenError.new(error_message, nil)
end
can_equal(other) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 129
def can_equal(other)
  other.is_a? Hocon::Impl::ConfigDelayedMergeObject
end
each() click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 172
def each
  raise self.class.not_resolved
end
empty?() click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 176
def empty?
  raise self.class.not_resolved
end
has_descendant?(descendant) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 66
def has_descendant?(descendant)
  Hocon::Impl::AbstractConfigValue.has_descendant_in_list?(@stack, descendant)
end
has_key?(key) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 164
def has_key?(key)
  raise self.class.not_resolved
end
has_value?(value) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 168
def has_value?(value)
  raise self.class.not_resolved
end
hash() click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 142
def hash
  # note that "origin" is deliberately NOT part of equality
  @stack.hash
end
ignores_fallbacks?() click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 78
def ignores_fallbacks?
  Hocon::Impl::ConfigDelayedMerge.stack_ignores_fallbacks?(@stack)
end
keys() click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 180
def keys
  raise self.class.not_resolved
end
make_replacement(context, skipping) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 49
def make_replacement(context, skipping)
  Hocon::Impl::ConfigDelayedMerge.make_replacement(context, @stack, skipping)
end
merged_with_non_object(fallback) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 92
def merged_with_non_object(fallback)
  require_not_ignoring_fallbacks

  merged_stack_with_non_object(@stack, fallback)
end
merged_with_object(fallback) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 88
def merged_with_object(fallback)
  merged_with_non_object(fallback)
end
merged_with_the_unmergeable(fallback) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 82
def merged_with_the_unmergeable(fallback)
  require_not_ignoring_fallbacks

  merged_stack_with_the_unmergeable(@stack, fallback)
end
new_copy(status, origin) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 36
def new_copy(status, origin)
  if status != resolve_status
    raise Hocon::ConfigError::ConfigBugOrBrokenError.new(
              "attempt to create resolved ConfigDelayedMergeObject")
  end
  Hocon::Impl::ConfigDelayedMergeObject.new(origin, @stack)
end
relativized(prefix) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 70
def relativized(prefix)
  new_stack = []
  @stack.each { |o|
    new_stack << o.relativized(prefix)
  }
  self.class.new(origin, new_stack)
end
render_to_sb(sb, indent, at_root, at_key, options) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 147
def render_to_sb(sb, indent, at_root, at_key, options)
  Hocon::Impl::ConfigDelayedMerge.render_value_to_sb_from_stack(@stack, sb, indent, at_root, at_key, options)
end
replace_child(child, replacement) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 57
def replace_child(child, replacement)
  new_stack = Hocon::Impl::AbstractConfigValue.replace_child_in_list(@stack, child, replacement)
  if new_stack == nil
    nil
  else
    self.class.new(origin, new_stack)
  end
end
resolve_status() click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 53
def resolve_status
  Hocon::Impl::ResolveStatus::UNRESOLVED
end
resolve_substitutions(context, source) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 44
def resolve_substitutions(context, source)
  merged = Hocon::Impl::ConfigDelayedMerge.resolve_substitutions(self, @stack, context, source)
  merged.as_object_result
end
size() click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 188
def size
  raise self.class.not_resolved
end
unmerged_values() click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 125
def unmerged_values
  @stack
end
unwrapped() click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 156
def unwrapped
  raise self.class.not_resolved
end
values() click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 184
def values
  raise self.class.not_resolved
end
with_only_key(key) click to toggle source

No implementation of withFallback here, just use the implementation in the super-class

# File lib/hocon/impl/config_delayed_merge_object.rb, line 101
def with_only_key(key)
  raise self.class.not_resolved
end
with_only_path(key) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 113
def with_only_path(key)
  raise self.class.not_resolved
end
with_only_path_or_nil(key) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 109
def with_only_path_or_nil(key)
  raise self.class.not_resolved
end
with_value(key_or_path, value = nil) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 121
def with_value(key_or_path, value = nil)
  raise self.class.not_resolved
end
without_key(key) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 105
def without_key(key)
  raise self.class.not_resolved
end
without_path(key) click to toggle source
# File lib/hocon/impl/config_delayed_merge_object.rb, line 117
def without_path(key)
  raise self.class.not_resolved
end