Class: Puppet::Pops::Types::TypeFormatter

Inherits:
Object
  • Object
show all
Extended by:
Concurrent::ThreadLocalSingleton
Defined in:
lib/puppet/pops/types/type_formatter.rb

Overview

API:

  • public

Direct Known Subclasses

RubyGenerator

Constant Summary collapse

NAME_SEGMENT_SEPARATOR =

API:

  • public

'::'
STARTS_WITH_ASCII_CAPITAL =

API:

  • public

/^[A-Z]/

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concurrent::ThreadLocalSingleton

singleton

Constructor Details

#initializeTypeFormatter

Returns a new instance of TypeFormatter.

API:

  • public



26
27
28
# File 'lib/puppet/pops/types/type_formatter.rb', line 26

def initialize
  @string_visitor = Visitor.new(nil, 'string', 0, 0)
end

Class Method Details

.string(t) ⇒ String

Produces a String representation of the given type.

Parameters:

  • the type to produce a string form

Returns:

  • the type in string form

API:

  • public



22
23
24
# File 'lib/puppet/pops/types/type_formatter.rb', line 22

def self.string(t)
  singleton.string(t)
end

Instance Method Details

#alias_expanded_string(t) ⇒ Object

Produces a string representing the type where type aliases have been expanded

API:

  • public



123
124
125
126
127
128
129
130
# File 'lib/puppet/pops/types/type_formatter.rb', line 123

def alias_expanded_string(t)
  @expanded = true
  begin
    string(t)
  ensure
    @expanded = false
  end
end

#append_callable_params(t) ⇒ Object

API:

  • public



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/puppet/pops/types/type_formatter.rb', line 294

def append_callable_params(t)
  # translate to string, and skip Unit types
  append_strings(t.param_types.types.reject { |t2| t2.instance_of?(PUnitType) }, true)

  if t.param_types.types.empty?
    append_strings([0, 0], true)
  else
    append_elements(range_array_part(t.param_types.size_type), true)
  end

  # Add block T last (after min, max) if present)
  #
  append_strings([t.block_type], true) unless t.block_type.nil?
  chomp_list
end

#append_defaultObject

API:

  • public



101
102
103
# File 'lib/puppet/pops/types/type_formatter.rb', line 101

def append_default
  @bld << 'default'
end

#append_indented_string(t, indent = 0, indent_width = 2, skip_initial_indent = false) ⇒ 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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/puppet/pops/types/type_formatter.rb', line 74

def append_indented_string(t, indent = 0, indent_width = 2, skip_initial_indent = false)
  save_indent = @indent
  save_indent_width = @indent_width
  @indent = indent
  @indent_width = indent_width
  begin
    (@indent * @indent_width).times { @bld << ' ' } unless skip_initial_indent
    append_string(t)
    @bld << "\n"
  ensure
    @indent = save_indent
    @indent_width = save_indent_width
  end
end

#append_string(t) ⇒ Object

API:

  • public



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/puppet/pops/types/type_formatter.rb', line 105

def append_string(t)
  if @ruby && t.is_a?(PAnyType)
    @ruby = false
    begin
      @bld << @ref_ctor << '('
      @string_visitor.visit_this_0(self, TypeFormatter.new.string(t))
      @bld << ')'
    ensure
      @ruby = true
    end
  else
    @string_visitor.visit_this_0(self, t)
  end
end

#capitalize_segments(qualified_name) ⇒ String

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.

Capitalizes each segment in a name separated with the NAME_SEPARATOR conditionally. The name will not be subject to capitalization if it already starts with a capital letter. This to avoid that existing camel casing is lost.

Parameters:

  • the name to capitalize

Returns:

  • the capitalized name

API:

  • private



644
645
646
647
648
649
650
651
652
653
654
655
656
# File 'lib/puppet/pops/types/type_formatter.rb', line 644

def capitalize_segments(qualified_name)
  if !qualified_name.is_a?(String) || qualified_name =~ STARTS_WITH_ASCII_CAPITAL
    qualified_name
  else
    segments = qualified_name.split(NAME_SEGMENT_SEPARATOR)
    if segments.size == 1
      qualified_name.capitalize
    else
      segments.each(&:capitalize!)
      segments.join(NAME_SEGMENT_SEPARATOR)
    end
  end
end

#debug_string(t) ⇒ Object

Produces a debug string representing the type (possibly with more information that the regular string format)

API:

  • public



135
136
137
138
139
140
141
142
# File 'lib/puppet/pops/types/type_formatter.rb', line 135

def debug_string(t)
  @debug = true
  begin
    string(t)
  ensure
    @debug = false
  end
end

#expandedObject

API:

  • public



30
31
32
33
34
# File 'lib/puppet/pops/types/type_formatter.rb', line 30

def expanded
  tf = clone
  tf.instance_variable_set(:@expanded, true)
  tf
end

#format_type_alias_type(t, expand) ⇒ 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



548
549
550
551
552
553
554
555
556
557
558
559
560
# File 'lib/puppet/pops/types/type_formatter.rb', line 548

def format_type_alias_type(t, expand)
  if @type_set.nil?
    @bld << t.name
    if expand && !Loader::StaticLoader::BUILTIN_ALIASES.include?(t.name)
      @bld << ' = '
      append_string(t.resolved_type)
    end
  elsif expand && @type_set.defines_type?(t)
    append_string(t.resolved_type)
  else
    @bld << @type_set.name_for(t, t.name)
  end
end

#indented(indent = 0, indent_width = 2) ⇒ Object

API:

  • public



36
37
38
39
40
41
# File 'lib/puppet/pops/types/type_formatter.rb', line 36

def indented(indent = 0, indent_width = 2)
  tf = clone
  tf.instance_variable_set(:@indent, indent)
  tf.instance_variable_set(:@indent_width, indent_width)
  tf
end

#indented_string(t, indent = 0, indent_width = 2) ⇒ Object

Produces an string containing newline characters and indentation that represents the given type or literal t.

Parameters:

  • the type or literal to produce a string for

  • (defaults to: 0)

    the current indentation level

  • (defaults to: 2)

    the number of spaces to use for one indentation

API:

  • public



67
68
69
70
71
# File 'lib/puppet/pops/types/type_formatter.rb', line 67

def indented_string(t, indent = 0, indent_width = 2)
  @bld = ''.dup
  append_indented_string(t, indent, indent_width)
  @bld
end

#ruby(ref_ctor) ⇒ Object

API:

  • public



43
44
45
46
47
48
# File 'lib/puppet/pops/types/type_formatter.rb', line 43

def ruby(ref_ctor)
  tf = clone
  tf.instance_variable_set(:@ruby, true)
  tf.instance_variable_set(:@ref_ctor, ref_ctor)
  tf
end

#ruby_string(ref_ctor, indent, t) ⇒ 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



90
91
92
93
94
95
96
97
98
99
# File 'lib/puppet/pops/types/type_formatter.rb', line 90

def ruby_string(ref_ctor, indent, t)
  @ruby = true
  @ref_ctor = ref_ctor
  begin
    indented_string(t, indent)
  ensure
    @ruby = nil
    @ref_ctor = nil
  end
end

#string(t) ⇒ Object

Produces a string representing the type

API:

  • public



53
54
55
56
57
# File 'lib/puppet/pops/types/type_formatter.rb', line 53

def string(t)
  @bld = ''.dup
  append_string(t)
  @bld
end

#string_Array(t) ⇒ 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



568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/puppet/pops/types/type_formatter.rb', line 568

def string_Array(t)
  append_array('') do
    if @indent && !is_short_array?(t)
      @indent += 1
      t.each { |elem| newline; append_string(elem); @bld << COMMA_SEP }
      chomp_list
      @indent -= 1
      newline
    else
      append_strings(t)
    end
  end
end

#string_FalseClass(t) ⇒ 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



583
# File 'lib/puppet/pops/types/type_formatter.rb', line 583

def string_FalseClass(t); @bld << 'false'; end

#string_Hash(t) ⇒ 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



586
587
588
# File 'lib/puppet/pops/types/type_formatter.rb', line 586

def string_Hash(t)
  append_hash(t)
end

#string_Module(t) ⇒ 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



591
592
593
# File 'lib/puppet/pops/types/type_formatter.rb', line 591

def string_Module(t)
  append_string(TypeCalculator.singleton.type(t))
end

#string_NilClass(t) ⇒ 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



596
# File 'lib/puppet/pops/types/type_formatter.rb', line 596

def string_NilClass(t); @bld << (@ruby ? 'nil' : 'undef'); end

#string_Numeric(t) ⇒ 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



599
# File 'lib/puppet/pops/types/type_formatter.rb', line 599

def string_Numeric(t); @bld << t.to_s; end

#string_Object(t) ⇒ Object

API:

  • public



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/puppet/pops/types/type_formatter.rb', line 339

def string_Object(t)
  type = TypeCalculator.infer(t)
  if type.is_a?(PObjectTypeExtension)
    type = type.base_type
  end
  if type.is_a?(PObjectType)
    init_hash = type.extract_init_hash(t)
    @bld << type.name << '('
    if @indent
      append_indented_string(init_hash, @indent, @indent_width, true)
      @bld.chomp!
    else
      append_string(init_hash)
    end
    @bld << ')'
  else
    @bld << 'Instance of '
    append_string(type)
  end
end

#string_PAnnotatedMember(m) ⇒ 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



455
456
457
458
459
460
461
462
# File 'lib/puppet/pops/types/type_formatter.rb', line 455

def string_PAnnotatedMember(m)
  hash = m._pcore_init_hash
  if hash.size == 1
    string(m.type)
  else
    string(hash)
  end
end

#string_PAnyType(_) ⇒ 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



145
# File 'lib/puppet/pops/types/type_formatter.rb', line 145

def string_PAnyType(_); @bld << 'Any'; end

#string_PArrayType(t) ⇒ 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



398
399
400
401
402
403
404
405
406
407
408
# File 'lib/puppet/pops/types/type_formatter.rb', line 398

def string_PArrayType(t)
  if t.has_empty_range?
    append_array('Array') { append_strings([0, 0]) }
  else
    append_array('Array', t == PArrayType::DEFAULT) do
      append_strings([t.element_type], true)
      append_elements(range_array_part(t.size_type), true)
      chomp_list
    end
  end
end

#string_PBinaryType(_) ⇒ 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



168
# File 'lib/puppet/pops/types/type_formatter.rb', line 168

def string_PBinaryType(_); @bld << 'Binary'; end

#string_PBooleanType(t) ⇒ 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



154
155
156
# File 'lib/puppet/pops/types/type_formatter.rb', line 154

def string_PBooleanType(t)
  append_array('Boolean', t.value.nil?) { append_string(t.value) }
end

#string_PCallableType(t) ⇒ 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



280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/puppet/pops/types/type_formatter.rb', line 280

def string_PCallableType(t)
  if t.return_type.nil?
    append_array('Callable', t.param_types.nil?) { append_callable_params(t) }
  elsif t.param_types.nil?
    append_array('Callable', false) { append_strings([[], t.return_type], false) }
  else
    append_array('Callable', false) do
      append_array('', false) { append_callable_params(t) }
      @bld << COMMA_SEP
      append_string(t.return_type)
    end
  end
end

#string_PCatalogEntryType(_) ⇒ 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



424
425
426
# File 'lib/puppet/pops/types/type_formatter.rb', line 424

def string_PCatalogEntryType(_)
  @bld << 'CatalogEntry'
end

#string_PClassType(t) ⇒ 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



429
430
431
# File 'lib/puppet/pops/types/type_formatter.rb', line 429

def string_PClassType(t)
  append_array('Class', t.class_name.nil?) { append_elements([t.class_name]) }
end

#string_PCollectionType(t) ⇒ 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



334
335
336
337
# File 'lib/puppet/pops/types/type_formatter.rb', line 334

def string_PCollectionType(t)
  range = range_array_part(t.size_type)
  append_array('Collection', range.empty?) { append_elements(range) }
end

#string_PDefaultType(_) ⇒ 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



151
# File 'lib/puppet/pops/types/type_formatter.rb', line 151

def string_PDefaultType(_); @bld << 'Default'; end

#string_PEnumType(t) ⇒ 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



219
220
221
222
223
224
225
226
227
# File 'lib/puppet/pops/types/type_formatter.rb', line 219

def string_PEnumType(t)
  append_array('Enum', t.values.empty?) do
    append_strings(t.values)
    if t.case_insensitive?
      @bld << COMMA_SEP
      append_string(true)
    end
  end
end

#string_PFloatType(t) ⇒ 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



196
197
198
# File 'lib/puppet/pops/types/type_formatter.rb', line 196

def string_PFloatType(t)
  append_array('Float', t.unbounded?) { append_elements(range_array_part(t)) }
end

#string_PHashType(t) ⇒ 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



411
412
413
414
415
416
417
418
419
420
421
# File 'lib/puppet/pops/types/type_formatter.rb', line 411

def string_PHashType(t)
  if t.has_empty_range?
    append_array('Hash') { append_strings([0, 0]) }
  else
    append_array('Hash', t == PHashType::DEFAULT) do
      append_strings([t.key_type, t.value_type], true)
      append_elements(range_array_part(t.size_type), true)
      chomp_list
    end
  end
end

#string_PInitType(t) ⇒ 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



181
182
183
# File 'lib/puppet/pops/types/type_formatter.rb', line 181

def string_PInitType(t)
  append_array('Init', t.type.nil?) { append_strings([t.type, *t.init_args]) }
end

#string_PIntegerType(t) ⇒ 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



171
172
173
# File 'lib/puppet/pops/types/type_formatter.rb', line 171

def string_PIntegerType(t)
  append_array('Integer', t.unbounded?) { append_elements(range_array_part(t)) }
end

#string_PIterableType(t) ⇒ 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



186
187
188
# File 'lib/puppet/pops/types/type_formatter.rb', line 186

def string_PIterableType(t)
  append_array('Iterable', t.element_type.nil?) { append_string(t.element_type) }
end

#string_PIteratorType(t) ⇒ 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



191
192
193
# File 'lib/puppet/pops/types/type_formatter.rb', line 191

def string_PIteratorType(t)
  append_array('Iterator', t.element_type.nil?) { append_string(t.element_type) }
end

#string_PNotUndefType(t) ⇒ 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



443
444
445
446
447
448
449
450
451
452
# File 'lib/puppet/pops/types/type_formatter.rb', line 443

def string_PNotUndefType(t)
  contained_type = t.type
  append_array('NotUndef', contained_type.nil? || contained_type.instance_of?(PAnyType)) do
    if contained_type.is_a?(PStringType) && !contained_type.value.nil?
      append_string(contained_type.value)
    else
      append_string(contained_type)
    end
  end
end

#string_PNumericType(_) ⇒ 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



165
# File 'lib/puppet/pops/types/type_formatter.rb', line 165

def string_PNumericType(_); @bld << 'Numeric'; end

#string_PObjectType(t) ⇒ 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



500
501
502
503
504
505
506
# File 'lib/puppet/pops/types/type_formatter.rb', line 500

def string_PObjectType(t)
  if @expanded
    append_object_hash(t._pcore_init_hash(@type_set.nil? || !@type_set.defines_type?(t)))
  else
    @bld << (@type_set ? @type_set.name_for(t, t.label) : t.label)
  end
end

#string_PObjectTypeExtension(t) ⇒ Object

API:

  • public



508
509
510
511
512
513
514
515
516
517
# File 'lib/puppet/pops/types/type_formatter.rb', line 508

def string_PObjectTypeExtension(t)
  append_array(@type_set ? @type_set.name_for(t, t.name) : t.name, false) do
    ips = t.init_parameters
    if ips.is_a?(Array)
      append_strings(ips)
    else
      append_string(ips)
    end
  end
end

#string_POptionalType(t) ⇒ 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



525
526
527
528
529
530
531
532
533
534
# File 'lib/puppet/pops/types/type_formatter.rb', line 525

def string_POptionalType(t)
  optional_type = t.optional_type
  append_array('Optional', optional_type.nil?) do
    if optional_type.is_a?(PStringType) && !optional_type.value.nil?
      append_string(optional_type.value)
    else
      append_string(optional_type)
    end
  end
end

#string_PPatternType(t) ⇒ 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



329
330
331
# File 'lib/puppet/pops/types/type_formatter.rb', line 329

def string_PPatternType(t)
  append_array('Pattern', t.patterns.empty?) { append_strings(t.patterns.map(&:regexp)) }
end

#string_PRegexpType(t) ⇒ 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



201
202
203
# File 'lib/puppet/pops/types/type_formatter.rb', line 201

def string_PRegexpType(t)
  append_array('Regexp', t.pattern.nil?) { append_string(t.regexp) }
end

#string_PResourceType(t) ⇒ 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



434
435
436
437
438
439
440
# File 'lib/puppet/pops/types/type_formatter.rb', line 434

def string_PResourceType(t)
  if t.type_name
    append_array(capitalize_segments(t.type_name), t.title.nil?) { append_string(t.title) }
  else
    @bld << 'Resource'
  end
end

#string_PRuntimeType(t) ⇒ 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



393
394
395
# File 'lib/puppet/pops/types/type_formatter.rb', line 393

def string_PRuntimeType(t)
  append_array('Runtime', t.runtime.nil? && t.name_or_pattern.nil?) { append_strings([t.runtime, t.name_or_pattern]) }
end

#string_PScalarDataType(_) ⇒ 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



162
# File 'lib/puppet/pops/types/type_formatter.rb', line 162

def string_PScalarDataType(_); @bld << 'ScalarData'; end

#string_PScalarType(_) ⇒ 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



159
# File 'lib/puppet/pops/types/type_formatter.rb', line 159

def string_PScalarType(_); @bld << 'Scalar'; end

#string_PSemVerRangeType(t) ⇒ 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



240
241
242
# File 'lib/puppet/pops/types/type_formatter.rb', line 240

def string_PSemVerRangeType(t)
  @bld << 'SemVerRange'
end

#string_PSemVerType(t) ⇒ 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



235
236
237
# File 'lib/puppet/pops/types/type_formatter.rb', line 235

def string_PSemVerType(t)
  append_array('SemVer', t.ranges.empty?) { append_strings(t.ranges) }
end

#string_PSensitiveType(t) ⇒ 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



520
521
522
# File 'lib/puppet/pops/types/type_formatter.rb', line 520

def string_PSensitiveType(t)
  append_array('Sensitive', PAnyType::DEFAULT == t.type) { append_string(t.type) }
end

#string_PStringType(t) ⇒ 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



206
207
208
209
210
211
212
213
214
215
216
# File 'lib/puppet/pops/types/type_formatter.rb', line 206

def string_PStringType(t)
  range = range_array_part(t.size_type)
  append_array('String', range.empty? && !(@debug && !t.value.nil?)) do
    if @debug
      append_elements(range, !t.value.nil?)
      append_string(t.value) unless t.value.nil?
    else
      append_elements(range)
    end
  end
end

#string_PStructType(t) ⇒ 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



311
312
313
# File 'lib/puppet/pops/types/type_formatter.rb', line 311

def string_PStructType(t)
  append_array('Struct', t.elements.empty?) { append_hash(t.elements.to_h { |e| struct_element_pair(e) }) }
end

#string_PTimespanType(t) ⇒ 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



258
259
260
261
262
263
264
265
266
267
268
# File 'lib/puppet/pops/types/type_formatter.rb', line 258

def string_PTimespanType(t)
  min = t.from
  max = t.to
  append_array('Timespan', min.nil? && max.nil?) do
    min.nil? ? append_default : append_string(min)
    unless max.nil? || max == min
      @bld << COMMA_SEP
      append_string(max)
    end
  end
end

#string_PTimestampType(t) ⇒ 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



245
246
247
248
249
250
251
252
253
254
255
# File 'lib/puppet/pops/types/type_formatter.rb', line 245

def string_PTimestampType(t)
  min = t.from
  max = t.to
  append_array('Timestamp', min.nil? && max.nil?) do
    min.nil? ? append_default : append_string(min)
    unless max.nil? || max == min
      @bld << COMMA_SEP
      append_string(max)
    end
  end
end

#string_PTupleType(t) ⇒ 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



271
272
273
274
275
276
277
# File 'lib/puppet/pops/types/type_formatter.rb', line 271

def string_PTupleType(t)
  append_array('Tuple', t.types.empty?) do
    append_strings(t.types, true)
    append_elements(range_array_part(t.size_type), true)
    chomp_list
  end
end

#string_PTypeAliasType(t) ⇒ 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



537
538
539
540
541
542
543
544
545
# File 'lib/puppet/pops/types/type_formatter.rb', line 537

def string_PTypeAliasType(t)
  expand = @expanded
  if expand && t.self_recursion?
    @guard ||= RecursionGuard.new
    @guard.with_this(t) { |state| format_type_alias_type(t, (state & RecursionGuard::SELF_RECURSION_IN_THIS) == 0) }
  else
    format_type_alias_type(t, expand)
  end
end

#string_PTypeReferenceType(t) ⇒ 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



563
564
565
# File 'lib/puppet/pops/types/type_formatter.rb', line 563

def string_PTypeReferenceType(t)
  append_array('TypeReference') { append_string(t.type_string) }
end

#string_PTypeSetType(t) ⇒ 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



472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/puppet/pops/types/type_formatter.rb', line 472

def string_PTypeSetType(t)
  append_array('TypeSet') do
    append_hash(t._pcore_init_hash.each, proc { |k| @bld << symbolic_key(k) }) do |k, v|
      case k
      when KEY_TYPES
        old_ts = @type_set
        @type_set = t
        begin
          append_hash(v, proc { |tk| @bld << symbolic_key(tk) }) do |_tk, tv|
            if tv.is_a?(Hash)
              append_object_hash(tv)
            else
              append_string(tv)
            end
          end
        rescue
          @type_set = old_ts
        end
      when KEY_REFERENCES
        append_hash(v, proc { |tk| @bld << symbolic_key(tk) })
      else
        append_string(v)
      end
    end
  end
end

#string_PTypeType(t) ⇒ 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



176
177
178
# File 'lib/puppet/pops/types/type_formatter.rb', line 176

def string_PTypeType(t)
  append_array('Type', t.type.nil?) { append_string(t.type) }
end

#string_PUndefType(_) ⇒ 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



148
# File 'lib/puppet/pops/types/type_formatter.rb', line 148

def string_PUndefType(_); @bld << 'Undef'; end

#string_PUnitType(_) ⇒ 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



388
389
390
# File 'lib/puppet/pops/types/type_formatter.rb', line 388

def string_PUnitType(_)
  @bld << 'Unit'
end

#string_PuppetObject(t) ⇒ Object

API:

  • public



360
361
362
363
364
365
366
367
368
369
# File 'lib/puppet/pops/types/type_formatter.rb', line 360

def string_PuppetObject(t)
  @bld << t._pcore_type.name << '('
  if @indent
    append_indented_string(t._pcore_init_hash, @indent, @indent_width, true)
    @bld.chomp!
  else
    append_string(t._pcore_init_hash)
  end
  @bld << ')'
end

#string_PURIType(t) ⇒ 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



372
373
374
# File 'lib/puppet/pops/types/type_formatter.rb', line 372

def string_PURIType(t)
  append_array('URI', t.parameters.nil?) { append_string(t._pcore_init_hash['parameters']) }
end

#string_PVariantType(t) ⇒ 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



230
231
232
# File 'lib/puppet/pops/types/type_formatter.rb', line 230

def string_PVariantType(t)
  append_array('Variant', t.types.empty?) { append_strings(t.types) }
end

#string_Regexp(t) ⇒ 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



602
# File 'lib/puppet/pops/types/type_formatter.rb', line 602

def string_Regexp(t); @bld << PRegexpType.regexp_to_s_with_delimiters(t); end

#string_String(t) ⇒ 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



605
606
607
608
# File 'lib/puppet/pops/types/type_formatter.rb', line 605

def string_String(t)
  # Use single qoute on strings that does not contain single quotes, control characters, or backslashes.
  @bld << StringConverter.singleton.puppet_quote(t)
end

#string_Symbol(t) ⇒ 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



611
# File 'lib/puppet/pops/types/type_formatter.rb', line 611

def string_Symbol(t); @bld << t.to_s; end

#string_Timespan(t) ⇒ 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



623
# File 'lib/puppet/pops/types/type_formatter.rb', line 623

def string_Timespan(t); @bld << "'#{t}'"; end

#string_Timestamp(t) ⇒ 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



626
# File 'lib/puppet/pops/types/type_formatter.rb', line 626

def string_Timestamp(t); @bld << "'#{t}'"; end

#string_TrueClass(t) ⇒ 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



614
# File 'lib/puppet/pops/types/type_formatter.rb', line 614

def string_TrueClass(t); @bld << 'true'; end

#string_URI(t) ⇒ Object

API:

  • public



376
377
378
379
380
381
382
383
384
385
# File 'lib/puppet/pops/types/type_formatter.rb', line 376

def string_URI(t)
  @bld << 'URI('
  if @indent
    append_indented_string(t.to_s, @indent, @indent_width, true)
    @bld.chomp!
  else
    append_string(t.to_s)
  end
  @bld << ')'
end

#string_Version(t) ⇒ 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



617
# File 'lib/puppet/pops/types/type_formatter.rb', line 617

def string_Version(t); @bld << "'#{t}'"; end

#string_VersionRange(t) ⇒ 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



620
# File 'lib/puppet/pops/types/type_formatter.rb', line 620

def string_VersionRange(t); @bld << "'#{t}'"; end

#struct_element_pair(t) ⇒ 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



316
317
318
319
320
321
322
323
324
325
326
# File 'lib/puppet/pops/types/type_formatter.rb', line 316

def struct_element_pair(t)
  k = t.key_type
  value_optional = t.value_type.assignable?(PUndefType::DEFAULT)
  if k.is_a?(POptionalType)
    # Output as literal String
    k = t.name if value_optional
  else
    k = value_optional ? PNotUndefType.new(k) : t.name
  end
  [k, t.value_type]
end

#symbolic_key(key) ⇒ 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.

Used when printing names of well known keys in an Object type. Placed in a separate method to allow override.

API:

  • private



467
468
469
# File 'lib/puppet/pops/types/type_formatter.rb', line 467

def symbolic_key(key)
  @ruby ? "'#{key}'" : key
end

#to_sObject

Debugging to_s to reduce the amount of output

API:

  • public



629
630
631
# File 'lib/puppet/pops/types/type_formatter.rb', line 629

def to_s
  '[a TypeFormatter]'
end