Mercurial > repos > other > Puppet
annotate modules/stdlib/lib/puppet/parser/functions/validate_email_address.rb @ 275:d9352a684e62
Mass update of modules to remove deprecation warnings
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 26 Jan 2020 11:36:07 +0000 |
parents | c42fb28cff86 |
children |
rev | line source |
---|---|
272 | 1 # |
2 # validate_email_address.rb | |
3 # | |
4 module Puppet::Parser::Functions | |
5 newfunction(:validate_email_address, :doc => <<-DOC | |
275
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
6 @summary |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
7 Validate that all values passed are valid email addresses. |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
8 Fail compilation if any value fails this check. |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
9 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
10 @return |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
11 Fail compilation if any value fails this check. |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
12 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
13 @example **Usage** |
272 | 14 |
275
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
15 The following values will pass: |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
16 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
17 $my_email = "waldo@gmail.com" |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
18 validate_email_address($my_email) |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
19 validate_email_address("bob@gmail.com", "alice@gmail.com", $my_email) |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
20 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
21 The following values will fail, causing compilation to abort: |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
22 |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
23 $some_array = [ 'bad_email@/d/efdf.com' ] |
d9352a684e62
Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
24 validate_email_address($some_array) |
272 | 25 DOC |
26 ) do |args| | |
27 rescuable_exceptions = [ArgumentError] | |
28 | |
29 if args.empty? | |
30 raise Puppet::ParseError, "validate_email_address(): wrong number of arguments (#{args.length}; must be > 0)" | |
31 end | |
32 | |
33 args.each do |arg| | |
34 raise Puppet::ParseError, "#{arg.inspect} is not a string." unless arg.is_a?(String) | |
35 | |
36 begin | |
37 raise Puppet::ParseError, "#{arg.inspect} is not a valid email address" unless function_is_email_address([arg]) | |
38 rescue *rescuable_exceptions | |
39 raise Puppet::ParseError, "#{arg.inspect} is not a valid email address" | |
40 end | |
41 end | |
42 end | |
43 end |