Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / validate_string.rb
1 #
2 # validate_String.rb
3 #
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.
8
9     The following values will pass:
10
11         $my_string = "one two"
12         validate_string($my_string, 'three')
13
14     The following values will fail, causing compilation to abort:
15
16         validate_string(true)
17         validate_string([ 'some', 'array' ])
18
19     Note: validate_string(undef) will not fail in this version of the
20     functions API (incl. current and future parser). Instead, use:
21
22         if $var == undef {
23           fail('...')
24         }
25
26     DOC
27
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.'])
30
31     if args.empty?
32       raise Puppet::ParseError, "validate_string(): wrong number of arguments (#{args.length}; must be > 0)"
33     end
34
35     args.each do |arg|
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}"
39       end
40     end
41   end
42 end