aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/functions/array_del.rb11
-rw-r--r--lib/puppet/parser/functions/join.rb10
-rw-r--r--lib/puppet/parser/functions/sha1.rb9
-rw-r--r--lib/puppet/parser/functions/split.rb23
-rw-r--r--lib/puppet/parser/functions/uniq_flatten.rb10
5 files changed, 31 insertions, 32 deletions
diff --git a/lib/puppet/parser/functions/array_del.rb b/lib/puppet/parser/functions/array_del.rb
new file mode 100644
index 0000000..e604916
--- /dev/null
+++ b/lib/puppet/parser/functions/array_del.rb
@@ -0,0 +1,11 @@
+Puppet::Parser::Functions::newfunction(
+ :array_del,
+ :type => :rvalue,
+ :doc => "Deletes items from an array
+
+ Example: array_del(['a','b'],'b') -> ['a']"
+) do |args|
+ raise Puppet::ParseError, 'array_del() needs two arguments' if args.length != 2
+ (res=args[0].dup).to_a.delete(args[1])
+ res
+end
diff --git a/lib/puppet/parser/functions/join.rb b/lib/puppet/parser/functions/join.rb
new file mode 100644
index 0000000..95b664c
--- /dev/null
+++ b/lib/puppet/parser/functions/join.rb
@@ -0,0 +1,10 @@
+Puppet::Parser::Functions::newfunction(
+ :join,
+ :type => :rvalue,
+ :doc => "Joins the values of the array in arg1 with the string in arg2
+
+ Example: join(['a','b'],',') -> 'a,b'"
+) do |args|
+ raise Puppet::ParseError, 'join() needs two arguments' if args.length != 2
+ args[0].to_a.join(args[1])
+end
diff --git a/lib/puppet/parser/functions/sha1.rb b/lib/puppet/parser/functions/sha1.rb
deleted file mode 100644
index b5aa813..0000000
--- a/lib/puppet/parser/functions/sha1.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# return the sha1 hash
-require 'digest/sha1'
-
-module Puppet::Parser::Functions
- newfunction(:sha1, :type => :rvalue) do |args|
- Digest::SHA1.hexdigest(args[0])
- end
-end
-
diff --git a/lib/puppet/parser/functions/split.rb b/lib/puppet/parser/functions/split.rb
deleted file mode 100644
index bffecc1..0000000
--- a/lib/puppet/parser/functions/split.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# This function has two modes of operation:
-#
-# split($string, $delimiter) : $string
-#
-# Split the first argument on every $delimiter. $delimiter is interpreted as
-# Ruby regular expression.
-#
-# split($string[], $delimiter) : $string[][]
-#
-# Returns an array of split results with the result of applying split to each
-# item from the first argument.
-#
-# For long-term portability it is recommended to refrain from using Ruby's
-# extended RE features.
-module Puppet::Parser::Functions
- newfunction(:split, :type => :rvalue) do |args|
- if args[0].is_a?(Array)
- args.collect do |a| a.split(/#{args[1]}/) end
- else
- args[0].split(/#{args[1]}/)
- end
- end
-end
diff --git a/lib/puppet/parser/functions/uniq_flatten.rb b/lib/puppet/parser/functions/uniq_flatten.rb
new file mode 100644
index 0000000..4841c4d
--- /dev/null
+++ b/lib/puppet/parser/functions/uniq_flatten.rb
@@ -0,0 +1,10 @@
+Puppet::Parser::Functions::newfunction(
+ :uniq_flatten,
+ :type => :rvalue,
+ :doc => "Flattens an array and make it uniq
+
+ Example: uniq_flatten([['a','b'],'a']) -> ['a','b']"
+) do |args|
+ raise Puppet::ParseError, 'uniq_flatten() needs one arguments' if args.length != 1
+ args[0].to_a.flatten.collect(&:to_s).uniq
+end