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:
904 bytes
|
Line | |
---|
1 | #
|
---|
2 | # chomp.rb
|
---|
3 | #
|
---|
4 |
|
---|
5 | module Puppet::Parser::Functions
|
---|
6 | newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS'
|
---|
7 | Removes the record separator from the end of a string or an array of
|
---|
8 | strings, for example `hello\n` becomes `hello`.
|
---|
9 | Requires a single string or array as an input.
|
---|
10 | EOS
|
---|
11 | ) do |arguments|
|
---|
12 |
|
---|
13 | raise(Puppet::ParseError, "chomp(): Wrong number of arguments " +
|
---|
14 | "given (#{arguments.size} for 1)") if arguments.size < 1
|
---|
15 |
|
---|
16 | value = arguments[0]
|
---|
17 |
|
---|
18 | unless value.is_a?(Array) || value.is_a?(String)
|
---|
19 | raise(Puppet::ParseError, 'chomp(): Requires either ' +
|
---|
20 | 'array or string to work with')
|
---|
21 | end
|
---|
22 |
|
---|
23 | if value.is_a?(Array)
|
---|
24 | # Numbers in Puppet are often string-encoded which is troublesome ...
|
---|
25 | result = value.collect { |i| i.is_a?(String) ? i.chomp : i }
|
---|
26 | else
|
---|
27 | result = value.chomp
|
---|
28 | end
|
---|
29 |
|
---|
30 | return result
|
---|
31 | end
|
---|
32 | end
|
---|
33 |
|
---|
34 | # vim: set ts=2 sw=2 et :
|
---|
Note:
See
TracBrowser
for help on using the repository browser.