Class: Puppet::Pops::Serialization::ObjectReader Private
- Includes:
- InstanceReader
- Defined in:
- lib/puppet/pops/serialization/object.rb
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.
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.
ObjectReader.new
Instance Method Summary collapse
Instance Method Details
#read(type, 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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/puppet/pops/serialization/object.rb', line 13 def read(type, impl_class, value_count, deserializer) (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 %{value0}. Expected %{required_count} - %{max}, actual %{value_count}") % { value0: impl_class.name, required_count: required_count, max: max, value_count: 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}[%{name}]") % { type_name: type.name, name: names[index] } unless attr && attr.value? args << attr.value end end val.send(:initialize, *args) val end |