Class: Puppet::Pops::Types::TypeMismatch Private

Inherits:
ExpectedActualMismatch show all
Includes:
LabelProvider
Defined in:
lib/puppet/pops/types/type_mismatch_describer.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.

Direct Known Subclasses

PatternMismatch

Constant Summary

Constants included from LabelProvider

LabelProvider::A, LabelProvider::AN, LabelProvider::SKIPPED_CHARACTERS, LabelProvider::VOWELS

Instance Attribute Summary

Attributes inherited from ExpectedActualMismatch

#actual, #expected

Attributes inherited from Mismatch

#path

Instance Method Summary collapse

Methods included from LabelProvider

#a_an, #a_an_uc, #article, #combine_strings, #plural_s, #the, #the_uc

Methods inherited from ExpectedActualMismatch

#==, #hash, #initialize

Methods inherited from Mismatch

#==, #canonical_path, #chop_path, #eql?, #format, #hash, #initialize, #path_string, #to_s

Constructor Details

This class inherits a constructor from Puppet::Pops::Types::ExpectedActualMismatch

Instance Method Details

#label(o) ⇒ 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.



323
324
325
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 323

def label(o)
  o.to_s
end

#merge(path, o) ⇒ 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.

Returns A new instance with the least restrictive respective boundaries.

Returns:

  • A new instance with the least restrictive respective boundaries



267
268
269
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 267

def merge(path, o)
  self.class.new(path, [expected, o.expected].flatten.uniq, actual)
end

#message(variant, position) ⇒ 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.



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 271

def message(variant, position)
  e = expected
  a = actual
  multi = false
  if e.is_a?(POptionalType)
    e = e.optional_type
    optional = true
  end

  if e.is_a?(PVariantType)
    e = e.types
  end

  if e.is_a?(Array)
    if report_detailed?(e, a)
      a = detailed_actual_to_s(e, a)
      e = e.map { |t| t.to_alias_expanded_s }
    else
      e = e.map { |t| t.simple_name }.uniq
      a = a.simple_name
    end
    e.insert(0, 'Undef') if optional
    case e.size
    when 1
      e = e[0]
    when 2
      e = "#{e[0]} or #{e[1]}"
      multi = true
    else
      e = "#{e[0..e.size-2].join(', ')}, or #{e[e.size-1]}"
      multi = true
    end
  else
    if report_detailed?(e, a)
      a = detailed_actual_to_s(e, a)
      e = e.to_alias_expanded_s
    else
      e = e.simple_name
      a = a.simple_name
    end
    if optional
      e = "Undef or #{e}"
      multi = true
    end
  end
  if multi
    "#{variant}#{position} expects a value of type #{e}, got #{label(a)}"
  else
    "#{variant}#{position} expects #{a_an(e)} value, got #{label(a)}"
  end
end