Update stdlib and concat to 6.1.0 both
[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
6     @summary
7       Validate that all passed values are string data structures
8
9     @return
10       Validate that all passed values are string data structures. Failed
11       compilation if any value fails this check.
12
13     @example **Usage**
14       The following values will pass:
15
16           $my_string = "one two"
17           validate_string($my_string, 'three')
18
19       The following values will fail, causing compilation to abort:
20
21           validate_string(true)
22           validate_string([ 'some', 'array' ])
23     > *Note:*
24     Validate_string(undef) will not fail in this version of the
25     functions API (incl. current and future parser). Instead, use:
26     ```
27       if $var == undef {
28          fail('...')
29         }
30     ```
31     DOC
32              ) do |args|
33     function_deprecation([:validate_string, 'This method is deprecated, please use the stdlib validate_legacy function,
34                             with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.'])
35
36     if args.empty?
37       raise Puppet::ParseError, "validate_string(): wrong number of arguments (#{args.length}; must be > 0)"
38     end
39
40     args.each do |arg|
41       # when called through the v4 API shim, undef gets translated to nil
42       unless arg.is_a?(String) || arg.nil?
43         raise Puppet::ParseError, "#{arg.inspect} is not a string.  It looks to be a #{arg.class}"
44       end
45     end
46   end
47 end