From b2f6f917f87792b373e21281fc1a55f0c1146474 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 2 Mar 2011 19:24:29 +0100 Subject: [PATCH] Filter functions --- .../lib/puppet/parser/functions/filter.rb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 modules/puppetmaster/lib/puppet/parser/functions/filter.rb diff --git a/modules/puppetmaster/lib/puppet/parser/functions/filter.rb b/modules/puppetmaster/lib/puppet/parser/functions/filter.rb new file mode 100644 index 000000000..e0dd34cdb --- /dev/null +++ b/modules/puppetmaster/lib/puppet/parser/functions/filter.rb @@ -0,0 +1,29 @@ +module Puppet::Parser::Functions + + # given an array of network addresses, return only the ipv4 addresses + newfunction(:filter_ipv4, :type => :rvalue) do |args| + x = args.shift + + raise Puppet::ParseError, "Argument is not an array." unless x.kind_of?(Array) + return x.reject{ |x| x =~ /:/} + end + + # given an array of network addresses, return only the ipv6 addresses + newfunction(:filter_ipv6, :type => :rvalue) do |args| + x = args.shift + + raise Puppet::ParseError, "Argument is not an array." unless x.kind_of?(Array) + return x.reject{ |x| x !~ /:/} + end + + # given an list, join with spaces + newfunction(:join_spc, :type => :rvalue) do |args| + x = args.shift + + raise Puppet::ParseError, "Argument is not an array." unless x.kind_of?(Array) + return x.join(' ') + end +end +# vim:set et: +# vim:set sts=2 ts=2: +# vim:set shiftwidth=2: -- 2.20.1