Class: Puppet::Pops::Serialization::ObjectWriter Private

Inherits:
Object
  • Object
show all
Includes:
InstanceWriter
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 writer for objects that implement Types::PuppetObject

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.

ObjectWriter.new

Instance Method Summary collapse

Instance Method Details

#write(type, value, serializer) ⇒ 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.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/puppet/pops/serialization/object.rb', line 43

def write(type, value, serializer)
  impl_class = value.class
  (names, _, required_count) = type.parameter_info(impl_class)
  args = names.map { |name| value.send(name) }

  # Pop optional arguments that are default
  while args.size > required_count
    break unless type[names[args.size-1]].default_value?(args.last)
    args.pop
  end

  if type.name.start_with?('Pcore::') || serializer.type_by_reference?
    serializer.push_written(value)
    serializer.start_pcore_object(type.name, args.size)
  else
    serializer.start_object(args.size + 1)
    serializer.write(type)
    serializer.push_written(value)
  end

  args.each { |arg| serializer.write(arg) }
end