Struct.new(:resource, :action, :notifying_resource)
# File lib/chef/resource.rb, line 35 def duplicates?(other_notification) unless other_notification.respond_to?(:resource) && other_notification.respond_to?(:action) msg = "only duck-types of Chef::Resource::Notification can be checked for duplication " "you gave #{other_notification.inspect}" raise ArgumentError, msg end other_notification.resource == resource && other_notification.action == action end
This will look up the notifying_resource if it is not a Resource Object. It will complain if it finds multiple resources, can't find a resource, or gets invalid syntax.
# File lib/chef/resource.rb, line 89 def fix_notifier_reference(resource_collection) matching_notifier = resource_collection.find(notifying_resource) if Array(matching_notifier).size > 1 msg = "Notification #{self} from #{notifying_resource} was created with a reference to multiple notifying " "resources, but can only originate from one resource. Destination resource was defined " "on #{resource.source_line}" raise Chef::Exceptions::InvalidResourceReference, msg end self.notifying_resource = matching_notifier rescue Chef::Exceptions::ResourceNotFound => e err = Chef::Exceptions::ResourceNotFound.new(Resource #{resource} is configured to receive notifications from #{notifying_resource} with action #{action}, \but #{notifying_resource} cannot be found in the resource collection. #{resource} is defined in \#{resource.source_line}) err.set_backtrace(e.backtrace) raise err rescue Chef::Exceptions::InvalidResourceSpecification => e err = Chef::Exceptions::InvalidResourceSpecification.new(Resource #{resource} is configured to receive notifications from #{notifying_resource} with action #{action}, \but #{notifying_resource.inspect} is not valid syntax to look up a resource in the resource collection. Notification \is defined near #{resource.source_line}) err.set_backtrace(e.backtrace) raise err end
This will look up the resource if it is not a Resource Object. It will complain if it finds multiple resources, can't find a resource, or gets invalid syntax.
# File lib/chef/resource.rb, line 60 def fix_resource_reference(resource_collection) matching_resource = resource_collection.find(resource) if Array(matching_resource).size > 1 msg = "Notification #{self} from #{notifying_resource} was created with a reference to multiple resources, " "but can only notify one resource. Notifying resource was defined on #{notifying_resource.source_line}" raise Chef::Exceptions::InvalidResourceReference, msg end self.resource = matching_resource rescue Chef::Exceptions::ResourceNotFound => e err = Chef::Exceptions::ResourceNotFound.new(resource #{notifying_resource} is configured to notify resource #{resource} with action #{action}, \but #{resource} cannot be found in the resource collection. #{notifying_resource} is defined in \#{notifying_resource.source_line}) err.set_backtrace(e.backtrace) raise err rescue Chef::Exceptions::InvalidResourceSpecification => e err = Chef::Exceptions::InvalidResourceSpecification.new(Resource #{notifying_resource} is configured to notify resource #{resource} with action #{action}, \but #{resource.inspect} is not valid syntax to look up a resource in the resource collection. Notification \is defined near #{notifying_resource.source_line}) err.set_backtrace(e.backtrace) raise err end
If resource and/or notifying_resource is not a resource object, this will look them up in the resource collection and fix the references from strings to actual Resource objects.
# File lib/chef/resource.rb, line 46 def resolve_resource_reference(resource_collection) return resource if resource.kind_of?(Chef::Resource) && notifying_resource.kind_of?(Chef::Resource) if not(resource.kind_of?(Chef::Resource)) fix_resource_reference(resource_collection) end if not(notifying_resource.kind_of?(Chef::Resource)) fix_notifier_reference(resource_collection) end end
Generated with the Darkfish Rdoc Generator 2.