]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/stdlib/lib/puppet/parser/functions/validate_string.rb
upgrade to concat 2.0.0
[dsa-puppet.git] / 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         $undefined = undef
17         validate_string($undefined)
18
19     ENDHEREDOC
20
21     unless args.length > 0 then
22       raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)")
23     end
24
25     args.each do |arg|
26       unless arg.is_a?(String)
27         raise Puppet::ParseError, ("#{arg.inspect} is not a string.  It looks to be a #{arg.class}")
28       end
29     end
30
31   end
32
33 end