]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/validate_string.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / validate_string.rb
1 module Puppet::Parser::Functions
2
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.
6
7     The following values will pass:
8
9         $my_string = "one two"
10         validate_string($my_string, 'three')
11
12     The following values will fail, causing compilation to abort:
13
14         validate_string(true)
15         validate_string([ 'some', 'array' ])
16         
17     Note: validate_string(undef) will not fail in this version of the
18     functions API (incl. current and future parser). Instead, use:
19     
20         if $var == undef {
21           fail('...')
22         }
23     
24     ENDHEREDOC
25
26     unless args.length > 0 then
27       raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)")
28     end
29
30     args.each do |arg|
31       unless arg.is_a?(String)
32         raise Puppet::ParseError, ("#{arg.inspect} is not a string.  It looks to be a #{arg.class}")
33       end
34     end
35
36   end
37
38 end