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