diff options
author | Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> | 2011-04-29 18:09:29 +0100 |
---|---|---|
committer | Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> | 2011-04-29 18:09:29 +0100 |
commit | a29674f08fbb85838d4d9cee5faea6303ef35b9b (patch) | |
tree | 68976aa643c480b4c4b5a54453391e7c62aa0ea1 | |
parent | c025cce133904890716da2349e7f3abbc6903c9e (diff) | |
download | puppet-stdlib-a29674f08fbb85838d4d9cee5faea6303ef35b9b.tar.gz puppet-stdlib-a29674f08fbb85838d4d9cee5faea6303ef35b9b.tar.bz2 |
First version. Simple rstrip function to use within Puppet DSL.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r-- | rstrip.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/rstrip.rb b/rstrip.rb new file mode 100644 index 0000000..b198488 --- /dev/null +++ b/rstrip.rb @@ -0,0 +1,31 @@ +# +# rstrip.rb +# + +module Puppet::Parser::Functions + newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "rstrip(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + if not [Array, String].include?(klass) + raise(Puppet::ParseError, 'rstrip(): Requires either an ' + + 'array or string to work with') + end + + if value.is_a?(Array) + result = value.collect { |i| i.is_a?(String) ? i.rstrip : i } + else + result = value.rstrip + end + + return result + end +end + +# vim: set ts=2 sw=2 et : |