Module: Puppet::Pops::Types::TypeAsserter
- Defined in:
- lib/puppet/pops/types/type_asserter.rb
Class Method Summary collapse
-
.assert_assignable(subject, expected_type, type_to_check, &block) ⇒ Object
Asserts that a type_to_check is assignable to required_type and raises a Puppet::ParseError if that’s not the case.
-
.assert_instance_of(subject, expected_type, value, nil_ok = false, &block) ⇒ Object
Asserts that a value is an instance of a given type and raises a Puppet::ParseError if that’s not the case.
Class Method Details
.assert_assignable(subject, expected_type, type_to_check, &block) ⇒ Object
Asserts that a type_to_check is assignable to required_type and raises a Puppet::ParseError if that’s not the case
17 18 19 20 |
# File 'lib/puppet/pops/types/type_asserter.rb', line 17 def self.assert_assignable(subject, expected_type, type_to_check, &block) report_type_mismatch(subject, expected_type, type_to_check, 'is incorrect', &block) unless expected_type.assignable?(type_to_check) type_to_check end |
.assert_instance_of(subject, expected_type, value, nil_ok = false, &block) ⇒ Object
Asserts that a value is an instance of a given type and raises a Puppet::ParseError if that’s not the case
33 34 35 36 37 38 |
# File 'lib/puppet/pops/types/type_asserter.rb', line 33 def self.assert_instance_of(subject, expected_type, value, nil_ok = false, &block) unless value.nil? && nil_ok report_type_mismatch(subject, expected_type, TypeCalculator.singleton.infer_set(value), &block) unless expected_type.instance?(value) end value end |