Last active
August 29, 2015 13:57
-
-
Save hlindberg/9731489 to your computer and use it in GitHub Desktop.
An assert_type function for puppet (untested example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Puppet::Parser::Functions::newfunction(:assert_type, :arity => 2, :type => :rvalue, :doc => | |
"Asserts that the given value has the given type and returns the value") do |args| | |
if Puppet::Pops::Types::TypeCalculator.instance?(args[0], args[1]) | |
args[1] | |
else | |
raise Puppet::ParseError, "The given value is not of type #{Puppet::Pops::Types::TypeCalculator.string(args[0])}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment