Last change
on this file since 30960 was 30960, checked in by davidb, 8 years ago |
Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster
|
File size:
818 bytes
|
Rev | Line | |
---|
[30960] | 1 | #
|
---|
| 2 | # strip.rb
|
---|
| 3 | #
|
---|
| 4 |
|
---|
| 5 | module Puppet::Parser::Functions
|
---|
| 6 | newfunction(:strip, :type => :rvalue, :doc => <<-EOS
|
---|
| 7 | This function removes leading and trailing whitespace from a string or from
|
---|
| 8 | every string inside an array.
|
---|
| 9 |
|
---|
| 10 | *Examples:*
|
---|
| 11 |
|
---|
| 12 | strip(" aaa ")
|
---|
| 13 |
|
---|
| 14 | Would result in: "aaa"
|
---|
| 15 | EOS
|
---|
| 16 | ) do |arguments|
|
---|
| 17 |
|
---|
| 18 | raise(Puppet::ParseError, "strip(): Wrong number of arguments " +
|
---|
| 19 | "given (#{arguments.size} for 1)") if arguments.size < 1
|
---|
| 20 |
|
---|
| 21 | value = arguments[0]
|
---|
| 22 |
|
---|
| 23 | unless value.is_a?(Array) || value.is_a?(String)
|
---|
| 24 | raise(Puppet::ParseError, 'strip(): Requires either ' +
|
---|
| 25 | 'array or string to work with')
|
---|
| 26 | end
|
---|
| 27 |
|
---|
| 28 | if value.is_a?(Array)
|
---|
| 29 | result = value.collect { |i| i.is_a?(String) ? i.strip : i }
|
---|
| 30 | else
|
---|
| 31 | result = value.strip
|
---|
| 32 | end
|
---|
| 33 |
|
---|
| 34 | return result
|
---|
| 35 | end
|
---|
| 36 | end
|
---|
| 37 |
|
---|
| 38 | # vim: set ts=2 sw=2 et :
|
---|
Note:
See
TracBrowser
for help on using the repository browser.