From 3827e73d67bece1b901d2bb2630a955aa737454c Mon Sep 17 00:00:00 2001 From: mh Date: Tue, 17 May 2011 21:10:40 +0200 Subject: add array union function --- lib/puppet/parser/functions/array_union.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/puppet/parser/functions/array_union.rb (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/array_union.rb b/lib/puppet/parser/functions/array_union.rb new file mode 100644 index 0000000..1ccad3f --- /dev/null +++ b/lib/puppet/parser/functions/array_union.rb @@ -0,0 +1,10 @@ +Puppet::Parser::Functions::newfunction( + :array_union, + :type => :rvalue, + :doc => "Unions two arrays + + Example: array_union(['a','b'],['c']) -> ['a','b','c']" +) do |args| + raise Puppet::ParseError, 'array_union() needs two arguments' if args.length != 2 + args[0].to_a | args[1].to_a +end -- cgit v1.2.3 From ad2be0a0f8eb24149761a8bade28ef9c222af1af Mon Sep 17 00:00:00 2001 From: mh Date: Tue, 17 May 2011 21:19:58 +0200 Subject: add hash_merge function --- lib/puppet/parser/functions/hash_merge.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/puppet/parser/functions/hash_merge.rb (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/hash_merge.rb b/lib/puppet/parser/functions/hash_merge.rb new file mode 100644 index 0000000..831c754 --- /dev/null +++ b/lib/puppet/parser/functions/hash_merge.rb @@ -0,0 +1,10 @@ +Puppet::Parser::Functions::newfunction( + :hash_merge, + :type => :rvalue, + :doc => "Merges two hashes + + Example: hash_merge({'a' => 1 ,'b' => 2},{'b' => 3, 'c' => 4}) -> {'a' => 1 ,'b' => 3, 'c' => 4}" +) do |args| + raise Puppet::ParseError, 'hash_merge() needs two arguments' if args.length != 2 + args[0].merge(args[1]) +end -- cgit v1.2.3 From e90839b24871f9cfd2166a116e45de5f27fe9e50 Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 8 Oct 2011 20:07:53 +0200 Subject: remove a couple of functions that can now be found in the puppetlabs stdlib --- lib/puppet/parser/functions/array_del.rb | 11 ----------- lib/puppet/parser/functions/hash_merge.rb | 10 ---------- lib/puppet/parser/functions/join.rb | 10 ---------- lib/puppet/parser/functions/strlength.rb | 6 ------ lib/puppet/parser/functions/uniq_flatten.rb | 10 ---------- 5 files changed, 47 deletions(-) delete mode 100644 lib/puppet/parser/functions/array_del.rb delete mode 100644 lib/puppet/parser/functions/hash_merge.rb delete mode 100644 lib/puppet/parser/functions/join.rb delete mode 100644 lib/puppet/parser/functions/strlength.rb delete mode 100644 lib/puppet/parser/functions/uniq_flatten.rb (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/array_del.rb b/lib/puppet/parser/functions/array_del.rb deleted file mode 100644 index e604916..0000000 --- a/lib/puppet/parser/functions/array_del.rb +++ /dev/null @@ -1,11 +0,0 @@ -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/hash_merge.rb b/lib/puppet/parser/functions/hash_merge.rb deleted file mode 100644 index 831c754..0000000 --- a/lib/puppet/parser/functions/hash_merge.rb +++ /dev/null @@ -1,10 +0,0 @@ -Puppet::Parser::Functions::newfunction( - :hash_merge, - :type => :rvalue, - :doc => "Merges two hashes - - Example: hash_merge({'a' => 1 ,'b' => 2},{'b' => 3, 'c' => 4}) -> {'a' => 1 ,'b' => 3, 'c' => 4}" -) do |args| - raise Puppet::ParseError, 'hash_merge() needs two arguments' if args.length != 2 - args[0].merge(args[1]) -end diff --git a/lib/puppet/parser/functions/join.rb b/lib/puppet/parser/functions/join.rb deleted file mode 100644 index 95b664c..0000000 --- a/lib/puppet/parser/functions/join.rb +++ /dev/null @@ -1,10 +0,0 @@ -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/strlength.rb b/lib/puppet/parser/functions/strlength.rb deleted file mode 100644 index 147b24a..0000000 --- a/lib/puppet/parser/functions/strlength.rb +++ /dev/null @@ -1,6 +0,0 @@ -module Puppet::Parser::Functions - newfunction(:strlength, :type => :rvalue) do |args| - args[0].to_s.length - end -end - diff --git a/lib/puppet/parser/functions/uniq_flatten.rb b/lib/puppet/parser/functions/uniq_flatten.rb deleted file mode 100644 index 4841c4d..0000000 --- a/lib/puppet/parser/functions/uniq_flatten.rb +++ /dev/null @@ -1,10 +0,0 @@ -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 -- cgit v1.2.3 From 50a1943175bd203116d100eb5cf4f01f2fc6ded1 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 8 Jun 2012 12:26:43 -0300 Subject: in 2.7 recmkdir is gone --- lib/puppet/parser/functions/tfile.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/tfile.rb b/lib/puppet/parser/functions/tfile.rb index a984892..acb6609 100644 --- a/lib/puppet/parser/functions/tfile.rb +++ b/lib/puppet/parser/functions/tfile.rb @@ -9,7 +9,8 @@ Puppet::Parser::Functions::newfunction( unless File.exists?(path) dir = File.dirname(path) unless File.directory?(dir) - Puppet::Util.recmkdir(dir,0700) + require 'fileutils' + FileUtils.mkdir_p(dir, :mode => 0700) end require 'fileutils' FileUtils.touch(path) -- cgit v1.2.3 From 4b4744e402f5cbc5f9856971d1a64002c7eb0796 Mon Sep 17 00:00:00 2001 From: o Date: Wed, 16 Apr 2014 14:21:32 +0200 Subject: add an array_join function --- lib/puppet/parser/functions/array_join.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 lib/puppet/parser/functions/array_join.rb (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/array_join.rb b/lib/puppet/parser/functions/array_join.rb new file mode 100644 index 0000000..c715c5d --- /dev/null +++ b/lib/puppet/parser/functions/array_join.rb @@ -0,0 +1,8 @@ +Puppet::Parser::Functions::newfunction(:array_join, + :type => :rvalue, + :doc => "Join a list of strings with an optional delimiter.") do |args| + unless 1..2.include? args.length + raise Puppet::ParseError, 'array_join() takes 1 or 2 arguments' + end + args.first.join args.last +end -- cgit v1.2.3 From 2bd349f9159a2b8d18805658033cfe91f1d5375d Mon Sep 17 00:00:00 2001 From: o Date: Wed, 16 Apr 2014 14:27:21 +0200 Subject: fix syntax --- lib/puppet/parser/functions/array_join.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/array_join.rb b/lib/puppet/parser/functions/array_join.rb index c715c5d..c5fa1c8 100644 --- a/lib/puppet/parser/functions/array_join.rb +++ b/lib/puppet/parser/functions/array_join.rb @@ -1,7 +1,7 @@ Puppet::Parser::Functions::newfunction(:array_join, :type => :rvalue, :doc => "Join a list of strings with an optional delimiter.") do |args| - unless 1..2.include? args.length + unless (1..2).include?(args.length) raise Puppet::ParseError, 'array_join() takes 1 or 2 arguments' end args.first.join args.last -- cgit v1.2.3 From ee7b4657fc32d87b62b257d267e68063fb232c53 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 25 Apr 2014 18:06:34 +0200 Subject: remove functions that are either covered with builtin functions or stdlib functions --- lib/puppet/parser/functions/array_include.rb | 11 ----------- lib/puppet/parser/functions/array_join.rb | 8 -------- lib/puppet/parser/functions/array_union.rb | 10 ---------- 3 files changed, 29 deletions(-) delete mode 100644 lib/puppet/parser/functions/array_include.rb delete mode 100644 lib/puppet/parser/functions/array_join.rb delete mode 100644 lib/puppet/parser/functions/array_union.rb (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/array_include.rb b/lib/puppet/parser/functions/array_include.rb deleted file mode 100644 index ce4748d..0000000 --- a/lib/puppet/parser/functions/array_include.rb +++ /dev/null @@ -1,11 +0,0 @@ -Puppet::Parser::Functions::newfunction( - :array_include, - :type => :rvalue, - :doc => "Checks whether an item is included or not - - Example: array_include(['a','b'],'b') -> true - Example: array_include(['a','b'],'c') -> false" -) do |args| - raise Puppet::ParseError, 'array_include() needs two arguments' if args.length != 2 - args[0].include?(args[1]) -end diff --git a/lib/puppet/parser/functions/array_join.rb b/lib/puppet/parser/functions/array_join.rb deleted file mode 100644 index c5fa1c8..0000000 --- a/lib/puppet/parser/functions/array_join.rb +++ /dev/null @@ -1,8 +0,0 @@ -Puppet::Parser::Functions::newfunction(:array_join, - :type => :rvalue, - :doc => "Join a list of strings with an optional delimiter.") do |args| - unless (1..2).include?(args.length) - raise Puppet::ParseError, 'array_join() takes 1 or 2 arguments' - end - args.first.join args.last -end diff --git a/lib/puppet/parser/functions/array_union.rb b/lib/puppet/parser/functions/array_union.rb deleted file mode 100644 index 1ccad3f..0000000 --- a/lib/puppet/parser/functions/array_union.rb +++ /dev/null @@ -1,10 +0,0 @@ -Puppet::Parser::Functions::newfunction( - :array_union, - :type => :rvalue, - :doc => "Unions two arrays - - Example: array_union(['a','b'],['c']) -> ['a','b','c']" -) do |args| - raise Puppet::ParseError, 'array_union() needs two arguments' if args.length != 2 - args[0].to_a | args[1].to_a -end -- cgit v1.2.3 From e9d8147584cf42dceec6d2cdd4314e8a85dc3aeb Mon Sep 17 00:00:00 2001 From: o Date: Thu, 9 Oct 2014 13:32:52 +0200 Subject: add a get_default function --- lib/puppet/parser/functions/get_default.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/puppet/parser/functions/get_default.rb (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/get_default.rb b/lib/puppet/parser/functions/get_default.rb new file mode 100644 index 0000000..3f4359b --- /dev/null +++ b/lib/puppet/parser/functions/get_default.rb @@ -0,0 +1,15 @@ +# get_default($value, $default) : $value +# +# return $value || $default. +module Puppet::Parser::Functions + newfunction(:get_default, :type => :rvalue) do |args| + value = nil + args.each { |x| + if ! x.nil? and x.length > 0 + value = x + break + end + } + return value + end +end -- cgit v1.2.3