Class: Puppet::Pops::Serialization::ObjectReader Private

Inherits:
Object
  • Object
show all
Includes:
InstanceReader
Defined in:
lib/puppet/pops/serialization/object.rb

Overview

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

Instance reader for objects that implement Types::PuppetObject

API:

  • private

Constant Summary collapse

INSTANCE =

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

API:

  • private

ObjectReader.new

Instance Method Summary collapse

Instance Method Details

#read(impl_class, value_count, deserializer) ⇒ 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.

API:

  • private



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet/pops/serialization/object.rb', line 12

def read(impl_class, value_count, deserializer)
  type = impl_class._ptype
  (names, types, required_count) = type.parameter_info(impl_class)
  max = names.size
  unless value_count >= required_count && value_count <= max
    raise Serialization::SerializationError, "Feature count mismatch for #{impl_class.name}. Expected #{required_count} - #{max}, actual #{value_count}"
  end
  # Deserializer must know about this instance before we read its attributes
  val = deserializer.remember(impl_class.allocate)
  args = Array.new(value_count) { deserializer.read }
  types.each_with_index do |ptype, index|
    if index < args.size
      arg = args[index]
      Types::TypeAsserter.assert_instance_of(nil, ptype, arg) { "#{type.name}[#{names[index]}]" } unless arg == :default
    else
      attr = type[names[index]]
      raise Serialization::SerializationError, "Missing default value for #{type.name}[#{names[index]}]" unless attr.value?
      args << attr.value
    end
  end
  val.send(:initialize, *args)
  val
end