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
15 16 17 18 |
# File 'lib/puppet/pops/types/type_asserter.rb', line 15 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
31 32 33 34 35 36 |
# File 'lib/puppet/pops/types/type_asserter.rb', line 31 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 |