From 37acfb9bc8675f33aef159f298e35e3e43998c4f Mon Sep 17 00:00:00 2001 From: luke Date: Fri, 26 Jan 2007 22:15:49 +0000 Subject: Fixing #442. You can now do: defined(File[...]) to see if a resource is defined. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2097 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/parser/functions.rb | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index 5f0930c6a..1174d7dad 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -151,14 +151,28 @@ module Functions # Test whether a given class or definition is defined newfunction(:defined, :type => :rvalue, :doc => "Determine whether a given - type is defined, either as a native type or a defined type.") do |vals| - # For some reason, it doesn't want me to return from here. - if vals.detect do |val| Puppet::Type.type(val) or finddefine(val) or findclass(val) end - true - else - false + type is defined, either as a native type or a defined type, or whether a resource has been + specified. If you are checking with a resource is defined, use the normal resource + reference syntax, e.g., ``File['/etc/passwd']``.") do |vals| + result = false + vals.each do |val| + case val + when String: + # For some reason, it doesn't want me to return from here. + if Puppet::Type.type(val) or finddefine(val) or findclass(val) + result = true + break + end + when Puppet::Parser::Resource::Reference: + if findresource(val.to_s) + result = true + break + end + else + raise ArgumentError, "Invalid argument of type %s to 'defined'" % val.class + end end - + result end newfunction(:fail, :doc => "Fail with a parse error.") do |vals| -- cgit