Method: Chef::ResourceCollection#find
- Defined in:
- lib/chef/resource_collection.rb
#find(*args) ⇒ Object Also known as: resources
Find existing resources by searching the list of existing resources. Possible forms are:
find(:file => “foobar”) find(:file => [ “foobar”, “baz” ]) find(“file“, ”file“) find(“file”)
Returns the matching resource, or an Array of matching resources.
Raises an ArgumentError if you feed it bad lookup information Raises a Runtime Error if it can’t find the resources you are looking for.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/chef/resource_collection.rb', line 136 def find(*args) results = Array.new args.each do |arg| case arg when Hash results << find_resource_by_hash(arg) when String results << find_resource_by_string(arg) else msg = "arguments to #{self.class.name}#find should be of the form :resource => 'name' or resource[name]" raise Chef::Exceptions::InvalidResourceSpecification, msg end end flat_results = results.flatten flat_results.length == 1 ? flat_results[0] : flat_results end |