diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-01-26 22:15:49 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-01-26 22:15:49 +0000 |
commit | 37acfb9bc8675f33aef159f298e35e3e43998c4f (patch) | |
tree | 1d46a52011169b71fa09fa358fd63aecb9ba0008 /lib/puppet/parser/functions.rb | |
parent | 2db68781a11de7b135d0abc332ed144c4e4b71c3 (diff) | |
download | puppet-37acfb9bc8675f33aef159f298e35e3e43998c4f.tar.gz puppet-37acfb9bc8675f33aef159f298e35e3e43998c4f.tar.xz puppet-37acfb9bc8675f33aef159f298e35e3e43998c4f.zip |
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
Diffstat (limited to 'lib/puppet/parser/functions.rb')
-rw-r--r-- | lib/puppet/parser/functions.rb | 28 |
1 files changed, 21 insertions, 7 deletions
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| |