Method: Puppet::Pops::Types::PTypeSetType#resolve_literal_hash

Defined in:
lib/puppet/pops/types/p_type_set_type.rb

#resolve_literal_hash(loader, init_hash_expression) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/puppet/pops/types/p_type_set_type.rb', line 269

def resolve_literal_hash(loader, init_hash_expression)
  result = {}
  type_parser = TypeParser.singleton
  init_hash_expression.entries.each do |entry|
    key = type_parser.interpret_any(entry.key, loader)
    if (key == KEY_TYPES || key == KEY_REFERENCES) && entry.value.is_a?(Model::LiteralHash)
      # Skip type parser interpretation and convert qualified references directly to String keys.
      hash = {}
      entry.value.entries.each do |he|
        kex = he.key
        name = kex.is_a?(Model::QualifiedReference) ? kex.cased_value : type_parser.interpret_any(kex, loader)
        hash[name] = key == KEY_TYPES ? he.value : type_parser.interpret_any(he.value, loader)
      end
      result[key] = hash
    else
      result[key] = type_parser.interpret_any(entry.value, loader)
    end
  end

  name_auth = resolve_name_authority(result, loader)

  types = result[KEY_TYPES]
  if types.is_a?(Hash)
    types.each do |type_name, value|
      full_name = "#{@name}::#{type_name}".freeze
      typed_name = Loader::TypedName.new(:type, full_name, name_auth)
      if value.is_a?(Model::ResourceDefaultsExpression)
        # This is actually a <Parent> { <key-value entries> } notation. Convert to a literal hash that contains the parent
        n = value.type_ref
        name = n.cased_value
        entries = []
        unless name == 'Object' or name == 'TypeSet'
          if value.operations.any? { |op| op.attribute_name == KEY_PARENT }
            case Puppet[:strict]
            when :warning
              IssueReporter.warning(value, Issues::DUPLICATE_KEY, :key => KEY_PARENT)
            when :error
              IssueReporter.error(Puppet::ParseErrorWithIssue, value, Issues::DUPLICATE_KEY, :key => KEY_PARENT)
            end
          end
          entries << Model::KeyedEntry.new(n.locator, n.offset, n.length, KEY_PARENT, n)
        end
        value.operations.each { |op| entries << Model::KeyedEntry.new(op.locator, op.offset, op.length, op.attribute_name, op.value_expr) }
        value = Model::LiteralHash.new(value.locator, value.offset, value.length, entries)
      end
      type = Loader::TypeDefinitionInstantiator.create_type(full_name, value, name_auth)
      loader.set_entry(typed_name, type, value.locator.to_uri(value))
      types[type_name] = type
    end
  end
  result
end