Method: Puppet::Pops::Types::TypeMismatchDescriber#validate_default_parameter

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

#validate_default_parameter(subject, param_name, param_type, value, tense = :ignored) ⇒ 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.

Parameters:

  • subject (String)

    string to be prepended to the exception message

  • param_name (String)

    parameter name

  • param_type (PAnyType)

    parameter type

  • value (Object)

    value to be validated against the given type

  • tense (Symbol) (defaults to: :ignored)

    deprecated and ignored



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

def validate_default_parameter(subject, param_name, param_type, value, tense = :ignored)
  tense_deprecated unless tense == :ignored
  unless param_type.instance?(value)
    errors = describe(param_type, TypeCalculator.singleton.infer_set(value).generalize, [ParameterPathElement.new(param_name)])
    case errors.size
    when 0
      # do nothing
    when 1
      raise Puppet::ParseError, "#{subject}:#{errors[0].format}"
    else
      errors_str = errors.map(&:format).join("\n ")
      raise Puppet::ParseError, "#{subject}:\n #{errors_str}"
    end
  end
end