Class: Chef::Resource::Notification
- Defined in:
- lib/chef/resource.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#notifying_resource ⇒ Object
Returns the value of attribute notifying_resource.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
- #duplicates?(other_notification) ⇒ Boolean
-
#fix_notifier_reference(resource_collection) ⇒ Object
This will look up the notifying_resource if it is not a Resource Object.
-
#fix_resource_reference(resource_collection) ⇒ Object
This will look up the resource if it is not a Resource Object.
-
#resolve_resource_reference(resource_collection) ⇒ Object
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.
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action
33 34 35 |
# File 'lib/chef/resource.rb', line 33 def action @action end |
#notifying_resource ⇒ Object
Returns the value of attribute notifying_resource
33 34 35 |
# File 'lib/chef/resource.rb', line 33 def @notifying_resource end |
#resource ⇒ Object
Returns the value of attribute resource
33 34 35 |
# File 'lib/chef/resource.rb', line 33 def resource @resource end |
Instance Method Details
#duplicates?(other_notification) ⇒ Boolean
35 36 37 38 39 40 41 42 |
# 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 |
#fix_notifier_reference(resource_collection) ⇒ Object
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.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/chef/resource.rb', line 89 def fix_notifier_reference(resource_collection) matching_notifier = resource_collection.find() if Array(matching_notifier).size > 1 msg = "Notification #{self} from #{} 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. = matching_notifier rescue Chef::Exceptions::ResourceNotFound => e err = Chef::Exceptions::ResourceNotFound.new(<<-FAIL) Resource #{resource} is configured to receive notifications from #{} with action #{action}, \ but #{} cannot be found in the resource collection. #{resource} is defined in \ #{resource.source_line} FAIL err.set_backtrace(e.backtrace) raise err rescue Chef::Exceptions::InvalidResourceSpecification => e err = Chef::Exceptions::InvalidResourceSpecification.new(<<-F) Resource #{resource} is configured to receive notifications from #{} with action #{action}, \ but #{.inspect} is not valid syntax to look up a resource in the resource collection. Notification \ is defined near #{resource.source_line} F err.set_backtrace(e.backtrace) raise err end |
#fix_resource_reference(resource_collection) ⇒ Object
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.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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 #{} was created with a reference to multiple resources, "\ "but can only notify one resource. Notifying resource was defined on #{.source_line}" raise Chef::Exceptions::InvalidResourceReference, msg end self.resource = matching_resource rescue Chef::Exceptions::ResourceNotFound => e err = Chef::Exceptions::ResourceNotFound.new(<<-FAIL) resource #{} is configured to notify resource #{resource} with action #{action}, \ but #{resource} cannot be found in the resource collection. #{} is defined in \ #{.source_line} FAIL err.set_backtrace(e.backtrace) raise err rescue Chef::Exceptions::InvalidResourceSpecification => e err = Chef::Exceptions::InvalidResourceSpecification.new(<<-F) 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 #{.source_line} F err.set_backtrace(e.backtrace) raise err end |
#resolve_resource_reference(resource_collection) ⇒ Object
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.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chef/resource.rb', line 46 def resolve_resource_reference(resource_collection) return resource if resource.kind_of?(Chef::Resource) && .kind_of?(Chef::Resource) if not(resource.kind_of?(Chef::Resource)) fix_resource_reference(resource_collection) end if not(.kind_of?(Chef::Resource)) fix_notifier_reference(resource_collection) end end |