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