summaryrefslogtreecommitdiff
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/parser/functions/glob.rb22
-rw-r--r--lib/puppet/provider/file_line/ruby.rb7
2 files changed, 28 insertions, 1 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
diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb
index fbf7d8e..42f287a 100644
--- a/lib/puppet/provider/file_line/ruby.rb
+++ b/lib/puppet/provider/file_line/ruby.rb
@@ -40,7 +40,12 @@ Puppet::Type.type(:file_line).provide(:ruby) do
# file; for now assuming that this type is only used on
# small-ish config files that can fit into memory without
# too much trouble.
- @lines ||= File.readlines(resource[:path], :encoding => resource[:encoding])
+ begin
+ @lines ||= File.readlines(resource[:path], :encoding => resource[:encoding])
+ rescue TypeError => e
+ # Ruby 1.8 doesn't support open_args
+ @lines ||= File.readlines(resource[:path])
+ end
end
def match_regex