Skip to content

Instantly share code, notes, and snippets.

@hlindberg
Last active August 29, 2015 13:57
Show Gist options
  • Save hlindberg/9731489 to your computer and use it in GitHub Desktop.
Save hlindberg/9731489 to your computer and use it in GitHub Desktop.
An assert_type function for puppet (untested example)
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