Last change
on this file since 30903 was 30903, checked in by davidb, 8 years ago |
Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details
|
File size:
967 bytes
|
Line | |
---|
1 | #
|
---|
2 | # regexpescape.rb
|
---|
3 | #
|
---|
4 | module Puppet::Parser::Functions
|
---|
5 | newfunction(:regexpescape, :type => :rvalue, :doc => <<-EOS
|
---|
6 | Regexp escape a string or array of strings.
|
---|
7 | Requires either a single string or an array as an input.
|
---|
8 | EOS
|
---|
9 | ) do |arguments| # rubocop:disable Style/ClosingParenthesisIndentation
|
---|
10 | raise(Puppet::ParseError, 'regexpescape(): Wrong number of arguments ' \
|
---|
11 | "given (#{arguments.size} for 1)") if arguments.empty?
|
---|
12 |
|
---|
13 | value = arguments[0]
|
---|
14 |
|
---|
15 | unless value.is_a?(Array) || value.is_a?(String)
|
---|
16 | raise(Puppet::ParseError, 'regexpescape(): Requires either ' \
|
---|
17 | 'array or string to work with')
|
---|
18 | end
|
---|
19 |
|
---|
20 | result = if value.is_a?(Array)
|
---|
21 | # Numbers in Puppet are often string-encoded which is troublesome ...
|
---|
22 | value.collect { |i| i.is_a?(String) ? Regexp.escape(i) : i }
|
---|
23 | else
|
---|
24 | Regexp.escape(value)
|
---|
25 | end
|
---|
26 |
|
---|
27 | return result
|
---|
28 | end
|
---|
29 | end
|
---|
30 |
|
---|
31 | # vim: set ts=2 sw=2 et :
|
---|
Note:
See
TracBrowser
for help on using the repository browser.