File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
lib/puppet/parser/functions Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ module Puppet ::Parser ::Functions
2
+
3
+ newfunction ( :validate_re , :doc => <<-'ENDHEREDOC' ) do |args |
4
+ Perform simple validation of a string against a regular expression. The second
5
+ argument of the function should be a string regular expression (without the //'s)
6
+ or an array of regular expressions. If none of the regular expressions in the array
7
+ match the string passed in, then an exception will be raised.
8
+
9
+ Example:
10
+
11
+ These strings validate against the regular expressions
12
+
13
+ validate_re('one', '^one$')
14
+ validate_re('one', [ '^one', '^two' ])
15
+
16
+ These strings do NOT validate
17
+
18
+ validate_re('one', [ '^two', '^three' ])
19
+
20
+
21
+
22
+ ENDHEREDOC
23
+ if args . length != 2 then
24
+ raise Puppet ::ParseError , ( "validate_re(): wrong number of arguments (#{ args . length } ; must be 2)" )
25
+ end
26
+
27
+ msg = "validate_re(): #{ args [ 0 ] . inspect } does not match #{ args [ 1 ] . inspect } "
28
+
29
+ raise Puppet ::ParseError , ( msg ) unless args [ 1 ] . any? do |re_str |
30
+ args [ 0 ] =~ Regexp . compile ( re_str )
31
+ end
32
+
33
+ end
34
+
35
+ end
You can’t perform that action at this time.
0 commit comments