1 module Puppet::Parser::Functions
3 newfunction(:validate_string, :doc => <<-'ENDHEREDOC') do |args|
4 Validate that all passed values are string data structures. Abort catalog
5 compilation if any value fails this check.
7 The following values will pass:
10 validate_string($my_string, 'three')
12 The following values will fail, causing compilation to abort:
15 validate_string([ 'some', 'array' ])
17 Note: validate_string(undef) will not fail in this version of the
18 functions API (incl. current and future parser). Instead, use:
26 function_deprecation([:validate_string, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.'])
28 unless args.length > 0 then
29 raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)")
33 # when called through the v4 API shim, undef gets translated to nil
34 unless arg.is_a?(String) || arg.nil?
35 raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}")