summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-18 23:08:32 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-18 23:08:32 +0000
commit66546610ceb5f14d7dce1da9286def4b1497bd60 (patch)
tree4a6b7e768ec06d28c1ab92dbfd28a018b5f7593c /lib/puppet/parser/functions.rb
parent5ecfd39340f70b8c49e53e2c472e92aeafde3992 (diff)
downloadpuppet-66546610ceb5f14d7dce1da9286def4b1497bd60.tar.gz
puppet-66546610ceb5f14d7dce1da9286def4b1497bd60.tar.xz
puppet-66546610ceb5f14d7dce1da9286def4b1497bd60.zip
Fixing #538. There is now a simple file() function to read in file contents.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2298 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/functions.rb')
-rw-r--r--lib/puppet/parser/functions.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb
index 0b94ca76e..cef694b85 100644
--- a/lib/puppet/parser/functions.rb
+++ b/lib/puppet/parser/functions.rb
@@ -231,6 +231,27 @@ module Functions
add_namespace(val)
end
end
+
+ newfunction(:file, :type => :rvalue,
+ :doc => "Return the contents of a file. Multiple files
+ can be passed, and the first file that exists will be read in.") do |vals|
+ ret = nil
+ vals.each do |file|
+ unless file =~ /^#{File::SEPARATOR}/
+ raise Puppet::ParseError, "Files must be fully qualified"
+ end
+ if FileTest.exists?(file)
+ ret = File.read(file)
+ break
+ end
+ end
+ if ret
+ ret
+ else
+ raise Puppet::ParseError, "Could not find any files from %s" %
+ vals.join(", ")
+ end
+ end
end
end