diff options
author | Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> | 2011-04-29 18:10:04 +0100 |
---|---|---|
committer | Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> | 2011-04-29 18:10:04 +0100 |
commit | 456a351ac2d7904c2c3bf4d106c1de679456325c (patch) | |
tree | 8ab96694e08bb8a50cae7fecb80c76c780ff2f57 | |
parent | 020a2a23eedcfb4957ac55214d597ec911e9b454 (diff) | |
download | puppet-stdlib-456a351ac2d7904c2c3bf4d106c1de679456325c.tar.gz puppet-stdlib-456a351ac2d7904c2c3bf4d106c1de679456325c.tar.bz2 |
First version. Simple chomp function to use within Puppet DSL.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r-- | chomp.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/chomp.rb b/chomp.rb new file mode 100644 index 0000000..bec3adf --- /dev/null +++ b/chomp.rb @@ -0,0 +1,31 @@ +# +# chomp.rb +# + +module Puppet::Parser::Functions + newfunction(:chomp, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "chomp(): 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, 'chomp(): Requires either an ' + + 'array or string to work with') + end + + if value.is_a?(Array) + result = value.collect { |i| i.is_a?(String) ? i.chomp : i } + else + result = value.chomp + end + + return result + end +end + +# vim: set ts=2 sw=2 et : |