summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWilson McCoubrey <wilson@mccoubreys.co.uk>2017-03-21 13:45:39 +0000
committerGitHub <noreply@github.com>2017-03-21 13:45:39 +0000
commitfd5c5765ddc68fae283cb6284efedf2011cc8a0e (patch)
tree66d64e0a011936c34f6a7e8e3bc1d8b20d8727fb /lib
parent9a6a33e3c9bef05dc6d5b02dddafcb82bead2271 (diff)
parent6092ede8d86746038df4a367191d232003652c55 (diff)
Merge pull request #718 from sspreitzer/master_glob
Add glob function
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/functions/glob.rb22
1 files changed, 22 insertions, 0 deletions
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