Method: Puppet::Pops::Types::StringConverter#string_PRuntimeType

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

#string_PRuntimeType(val_type, val, format_map, indent) ⇒ 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.



582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/puppet/pops/types/string_converter.rb', line 582

def string_PRuntimeType(val_type, val, format_map, indent)
  # Before giving up on this, and use a string representation of the unknown
  # object, a check is made to see if the object can present itself as
  # a hash or an array. If it can, then that representation is used instead.
  if val.is_a?(Hash)
    hash = val.to_hash
    # Ensure that the returned value isn't derived from Hash
    return string_PHashType(val_type, hash, format_map, indent) if hash.instance_of?(Hash)
  elsif val.is_a?(Array)
    array = val.to_a
    # Ensure that the returned value isn't derived from Array
    return string_PArrayType(val_type, array, format_map, indent) if array.instance_of?(Array)
  end

  f = get_format(val_type, format_map)
  case f.format
  when :s
    val.to_s
  when :p
    puppet_quote(val.to_s)
  when :q
    val.inspect
  else
    raise FormatError.new('Runtime', f.format, 'spq')
  end
end