Module: Puppet::Pops::Types::TypeAsserter

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

Overview

Utility module for type assertion

Class Method Summary collapse

Class Method Details

.assert_assignable(subject, expected_type, type_to_check) ⇒ Object

Asserts that a type_to_check is assignable to required_type and raises a Puppet::ParseError if that’s not the case



12
13
14
15
# File 'lib/puppet/pops/types/type_asserter.rb', line 12

def self.assert_assignable(subject, expected_type, type_to_check)
  check_assignability(Puppet::Pops::Types::TypeCalculator.singleton, subject, expected_type, type_to_check)
  type_to_check
end

.assert_instance_of(subject, expected_type, value, nil_ok = false) ⇒ Object

Asserts that a value is an instance of a given type and raises a Puppet::ParseError if that’s not the case



26
27
28
29
30
31
32
# File 'lib/puppet/pops/types/type_asserter.rb', line 26

def self.assert_instance_of(subject, expected_type, value, nil_ok = false)
  if !(value.nil? && nil_ok)
    tc = Puppet::Pops::Types::TypeCalculator.singleton
    check_assignability(tc, subject, expected_type, tc.infer_set(value), true)
  end
  value
end