source: other-projects/hathitrust/vagrant-solr-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/validate_string.rb@ 30960

Last change on this file since 30960 was 30960, checked in by davidb, 7 years ago

Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster

File size: 1.3 KB
Line 
1module 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 function_deprecation([:validate_string, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.'])
27
28 unless args.length > 0 then
29 raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)")
30 end
31
32 args.each do |arg|
33 # when called through the v4 API shim, undef gets translated to nil
34 unless arg.is_a?(String) || arg.nil?
35 raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}")
36 end
37 end
38
39 end
40
41end
Note: See TracBrowser for help on using the repository browser.