Module: Hocon::Impl::AbstractConfigObject

Includes:
ConfigObject, AbstractConfigValue, Container
Included in:
ConfigDelayedMergeObject, SimpleConfigObject
Defined in:
lib/hocon/impl/abstract_config_object.rb

Constant Summary collapse

ConfigBugOrBrokenError =
Hocon::ConfigError::ConfigBugOrBrokenError
ConfigNotResolvedError =
Hocon::ConfigError::ConfigNotResolvedError

Constants included from AbstractConfigValue

Hocon::Impl::AbstractConfigValue::ConfigImplUtil, Hocon::Impl::AbstractConfigValue::ResolveStatus

Instance Attribute Summary

Attributes included from AbstractConfigValue

#origin

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AbstractConfigValue

#==, #at_key, #at_key_with_origin, #at_path, #at_path_with_origin, #can_equal, #delay_merge, has_descendant_in_list?, #hash, #ignores_fallbacks?, indent, #inspect, #merged_stack_with_non_object, #merged_stack_with_object, #merged_stack_with_the_unmergeable, #merged_with_non_object, #merged_with_the_unmergeable, #render, #render_to_sb, replace_child_in_list, #require_not_ignoring_fallbacks, #resolve_status, #to_s, #transform_to_string, #with_fallbacks_ignored

Methods included from ConfigValue

#at_key, #at_path, #origin, #render, #unwrapped

Methods included from Container

#has_descendant?, #replace_child

Methods included from ConfigObject

#get, #unwrapped

Class Method Details

.merge_origins(stack) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/hocon/impl/abstract_config_object.rb', line 144

def self.merge_origins(stack)
  if stack.empty?
    raise ConfigBugOrBrokenError, "can't merge origins on empty list"
  end
  origins = []
  first_origin = nil
  num_merged = 0
  stack.each do |v|
    if first_origin.nil?
      first_origin = v.origin
    end

    if (v.is_a?(Hocon::Impl::AbstractConfigObject)) &&
        (v.resolve_status == Hocon::Impl::ResolveStatus::RESOLVED) &&
        v.empty?
      # don't include empty files or the .empty()
      # config in the description, since they are
      # likely to be "implementation details"
    else
      origins.push(v.origin)
      num_merged += 1
    end
  end

  if num_merged == 0
    # the configs were all empty, so just use the first one
    origins.push(first_origin)
  end

  Hocon::Impl::SimpleConfigOrigin.merge_origins(origins)
end

Instance Method Details

#[](key) ⇒ Object



184
185
186
# File 'lib/hocon/impl/abstract_config_object.rb', line 184

def [](key)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `[]`"
end

#[]=(key, value) ⇒ Object



200
201
202
# File 'lib/hocon/impl/abstract_config_object.rb', line 200

def []=(key, value)
  raise we_are_immutable("[]=")
end

#attempt_peek_with_partial_resolve(key) ⇒ Object

Look up the key on an only-partially-resolved object, with no transformation or type conversion of any kind; if ‘this’ is not resolved then try to look up the key anyway if possible.

Parameters:

  • key

    key to look up

Returns:

  • the value of the key, or null if known not to exist

Raises:



89
90
91
# File 'lib/hocon/impl/abstract_config_object.rb', line 89

def attempt_peek_with_partial_resolve(key)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `attempt_peek_with_partial_resolve`"
end

#clearObject



196
197
198
# File 'lib/hocon/impl/abstract_config_object.rb', line 196

def clear
  raise we_are_immutable("clear")
end

#construct_delayed_merge(origin, stack) ⇒ Object



132
133
134
# File 'lib/hocon/impl/abstract_config_object.rb', line 132

def construct_delayed_merge(origin, stack)
  Hocon::Impl::ConfigDelayedMergeObject.new(origin, stack)
end

#delete(key) ⇒ Object



212
213
214
# File 'lib/hocon/impl/abstract_config_object.rb', line 212

def delete(key)
  raise we_are_immutable("delete")
end

#initialize(origin) ⇒ Object



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

def initialize(origin)
  super(origin)
  @config = Hocon::Impl::SimpleConfig.new(self)
end

#merged_with_object(fallback) ⇒ Object



136
137
138
# File 'lib/hocon/impl/abstract_config_object.rb', line 136

def merged_with_object(fallback)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `merged_with_object`"
end

#new_copy(origin) ⇒ Object



128
129
130
# File 'lib/hocon/impl/abstract_config_object.rb', line 128

def new_copy(origin)
  new_copy_with_status(resolve_status, origin)
end

#new_copy_with_status(status, origin) ⇒ Object



124
125
126
# File 'lib/hocon/impl/abstract_config_object.rb', line 124

def new_copy_with_status(status, origin)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `new_copy_with_status`"
end

#peek_assuming_resolved(key, original_path) ⇒ Object

This looks up the key with no transformation or type conversion of any kind, and returns null if the key is not present. The object must be resolved along the nodes needed to get the key or ConfigNotResolvedError will be thrown.

Parameters:

  • key

Returns:

  • the unmodified raw value or null



71
72
73
74
75
76
77
# File 'lib/hocon/impl/abstract_config_object.rb', line 71

def peek_assuming_resolved(key, original_path)
  begin
    attempt_peek_with_partial_resolve(key)
  rescue ConfigNotResolvedError => e
    raise Hocon::Impl::ConfigImpl.improve_not_resolved(original_path, e)
  end
end

#peek_path(path) ⇒ Object

Looks up the path with no transformation or type conversion. Returns null if the path is not found; throws ConfigException.NotResolved if we need to go through an unresolved node to look up the path.



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

def peek_path(path)
  peek_path_from_obj(self, path)
end

#peek_path_from_obj(obj, path) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/hocon/impl/abstract_config_object.rb', line 100

def peek_path_from_obj(obj, path)
  begin
    # we'll fail if anything along the path can't be looked at without resolving
    path_next = path.remainder
    v = obj.attempt_peek_with_partial_resolve(path.first)

    if path_next.nil?
      v
    else
      if v.is_a?(Hocon::Impl::AbstractConfigObject)
        peek_path_from_obj(v, path_next)
      else
        nil
      end
    end
  rescue ConfigNotResolvedError => e
    raise Hocon::Impl::ConfigImpl.improve_not_resolved(path, e)
  end
end

#putAll(map) ⇒ Object



204
205
206
# File 'lib/hocon/impl/abstract_config_object.rb', line 204

def putAll(map)
  raise we_are_immutable("putAll")
end

#relativized(path) ⇒ Object



180
181
182
# File 'lib/hocon/impl/abstract_config_object.rb', line 180

def relativized(path)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `relativized`"
end

#remove(key) ⇒ Object



208
209
210
# File 'lib/hocon/impl/abstract_config_object.rb', line 208

def remove(key)
  raise we_are_immutable("remove")
end

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



188
189
190
# File 'lib/hocon/impl/abstract_config_object.rb', line 188

def render_value_to_sb(sb, indent, at_root, options)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `render_value_to_sb`"
end

#resolve_substitutions(context, source) ⇒ Object



176
177
178
# File 'lib/hocon/impl/abstract_config_object.rb', line 176

def resolve_substitutions(context, source)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `resolve_substituions`"
end

#to_configObject



28
29
30
# File 'lib/hocon/impl/abstract_config_object.rb', line 28

def to_config
  @config
end

#to_fallback_valueObject



32
33
34
# File 'lib/hocon/impl/abstract_config_object.rb', line 32

def to_fallback_value
  self
end

#value_typeObject



120
121
122
# File 'lib/hocon/impl/abstract_config_object.rb', line 120

def value_type
  Hocon::ConfigValueType::OBJECT
end

#we_are_immutable(method) ⇒ Object



192
193
194
# File 'lib/hocon/impl/abstract_config_object.rb', line 192

def we_are_immutable(method)
  Hocon::Impl::UnsupportedOperationError.new("ConfigObject is immutable, you can't call Map.#{method}")
end

#with_fallback(mergeable) ⇒ Object



140
141
142
# File 'lib/hocon/impl/abstract_config_object.rb', line 140

def with_fallback(mergeable)
  super(mergeable)
end

#with_only_key(key) ⇒ Object



36
37
38
# File 'lib/hocon/impl/abstract_config_object.rb', line 36

def with_only_key(key)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `with_only_key`"
end

#with_only_path(path) ⇒ Object



52
53
54
# File 'lib/hocon/impl/abstract_config_object.rb', line 52

def with_only_path(path)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `with_only_path`"
end

#with_only_path_or_nil(path) ⇒ Object



48
49
50
# File 'lib/hocon/impl/abstract_config_object.rb', line 48

def with_only_path_or_nil(path)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `with_only_path_or_nil`"
end

#with_origin(origin) ⇒ Object



216
217
218
# File 'lib/hocon/impl/abstract_config_object.rb', line 216

def with_origin(origin)
  super(origin)
end

#with_path_value(path, value) ⇒ Object



60
61
62
# File 'lib/hocon/impl/abstract_config_object.rb', line 60

def with_path_value(path, value)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `with_path_value`"
end

#with_value(key, value) ⇒ Object



44
45
46
# File 'lib/hocon/impl/abstract_config_object.rb', line 44

def with_value(key, value)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `with_value`"
end

#without_key(key) ⇒ Object



40
41
42
# File 'lib/hocon/impl/abstract_config_object.rb', line 40

def without_key(key)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `without_key`"
end

#without_path(path) ⇒ Object



56
57
58
# File 'lib/hocon/impl/abstract_config_object.rb', line 56

def without_path(path)
  raise ConfigBugOrBrokenError, "subclasses of AbstractConfigObject should override `without_path`"
end