From 6092ede8d86746038df4a367191d232003652c55 Mon Sep 17 00:00:00 2001 From: Sascha Spreitzer Date: Sat, 4 Feb 2017 13:30:59 +0100 Subject: Add glob function --- lib/puppet/parser/functions/glob.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/puppet/parser/functions/glob.rb (limited to 'lib') diff --git a/lib/puppet/parser/functions/glob.rb b/lib/puppet/parser/functions/glob.rb new file mode 100644 index 0000000..54cdda6 --- /dev/null +++ b/lib/puppet/parser/functions/glob.rb @@ -0,0 +1,22 @@ +# +# glob.rb +# + +module Puppet::Parser::Functions + newfunction(:glob, :type => :rvalue, :doc => <<-'EOS' + Returns an Array of file entries of a directory or an Array of directories. + Uses same patterns as Dir#glob + EOS + ) do |arguments| + + raise(Puppet::ParseError, "glob(): Wrong number of arguments given " + + "(#{arguments.size} for 1)") unless arguments.size == 1 + + pattern = arguments[0] + + raise(Puppet::ParseError, 'glob(): Requires either array or string ' + + 'to work') unless pattern.is_a?(String) || pattern.is_a?(Array) + + Dir.glob(pattern) + end +end -- cgit v1.2.3