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, #plural_s, #the, #the_uc

Methods inherited from ExpectedActualMismatch

#==, #hash, #initialize, #swap_expected

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.



362
363
364
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 362

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



318
319
320
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 318

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.



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 322

def message(variant, position)
  e = expected
  a = actual
  multi = false
  if e.is_a?(PVariantType)
    e = e.types
    if report_detailed?(e, a)
      a = detailed_actual_to_s(e, a)
      e = e.map { |t| t.to_alias_expanded_s }
    else
      sns = e.map { |t| t.simple_name }.uniq
      e = e.map { |t| s = t.simple_name; sns.count {|x| x == s } == 1 ? s : t.to_s }.uniq
      a = a.simple_name
    end
    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
  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