From 259be7a0cb3f7d7f7ee4d0f49211ddc8d9dcc1b9 Mon Sep 17 00:00:00 2001 From: Noah Kantrowitz Date: Thu, 28 Jul 2016 16:11:42 -0700 Subject: Remove some (hopefully) vestigial code related to notification storage. John K and I are 99% sure those branches have never been used outside of unit tests. Fingers crossed! --- lib/chef/run_context.rb | 48 ++++++------------------------------------------ 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb index 29c936a932..89247d46bb 100644 --- a/lib/chef/run_context.rb +++ b/lib/chef/run_context.rb @@ -194,12 +194,7 @@ class Chef # @param [Chef::Resource::Notification] The notification to add. # def notifies_before(notification) - nr = notification.notifying_resource - if nr.instance_of?(Chef::Resource) - before_notification_collection[nr.name] << notification - else - before_notification_collection[nr.declared_key] << notification - end + before_notification_collection[notification.notifying_resource.declared_key] << notification end # @@ -208,12 +203,7 @@ class Chef # @param [Chef::Resource::Notification] The notification to add. # def notifies_immediately(notification) - nr = notification.notifying_resource - if nr.instance_of?(Chef::Resource) - immediate_notification_collection[nr.name] << notification - else - immediate_notification_collection[nr.declared_key] << notification - end + immediate_notification_collection[notification.notifying_resource.declared_key] << notification end # @@ -222,12 +212,7 @@ class Chef # @param [Chef::Resource::Notification] The notification to add. # def notifies_delayed(notification) - nr = notification.notifying_resource - if nr.instance_of?(Chef::Resource) - delayed_notification_collection[nr.name] << notification - else - delayed_notification_collection[nr.declared_key] << notification - end + delayed_notification_collection[notification.notifying_resource.declared_key] << notification end # @@ -245,50 +230,29 @@ class Chef # # Get the list of before notifications sent by the given resource. # - # TODO seriously, this is actually wrong. resource.name is not unique, - # you need the type as well. - # # @return [Array[Notification]] # def before_notifications(resource) - if resource.instance_of?(Chef::Resource) - return before_notification_collection[resource.name] - else - return before_notification_collection[resource.declared_key] - end + return before_notification_collection[resource.declared_key] end # # Get the list of immediate notifications sent by the given resource. # - # TODO seriously, this is actually wrong. resource.name is not unique, - # you need the type as well. - # # @return [Array[Notification]] # def immediate_notifications(resource) - if resource.instance_of?(Chef::Resource) - return immediate_notification_collection[resource.name] - else - return immediate_notification_collection[resource.declared_key] - end + return immediate_notification_collection[resource.declared_key] end # # Get the list of delayed (end of run) notifications sent by the given # resource. # - # TODO seriously, this is actually wrong. resource.name is not unique, - # you need the type as well. - # # @return [Array[Notification]] # def delayed_notifications(resource) - if resource.instance_of?(Chef::Resource) - return delayed_notification_collection[resource.name] - else - return delayed_notification_collection[resource.declared_key] - end + return delayed_notification_collection[resource.declared_key] end # -- cgit v1.2.1 From 56af1a3713cd4f408c2c1d8658961c7b5df73192 Mon Sep 17 00:00:00 2001 From: Noah Kantrowitz Date: Thu, 28 Jul 2016 17:14:20 -0700 Subject: So this was less vestigial than we thought. Those Chef::Resource instances are created when subscribing against a string key. Leaving the conditionals removed, but adding a new stubby class to streamline things and a note on the RunContext side so we might remember how this works next time. --- lib/chef/resource.rb | 14 +++++++++++++- lib/chef/run_context.rb | 9 +++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 262aa84781..479eb0a7e2 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -259,6 +259,18 @@ class Chef true end + # + # Token class to hold an unresolved subscribes call with an associated + # run context. + # + # @api private + # @see Resource#subscribes + class UnresolvedSubscribes < self + # The full key ise given as the name in {Resource#subscribes} + alias_method :to_s, :name + alias_method :declared_key, :name + end + # # Subscribes to updates from other resources, causing a particular action to # run on *this* resource when the other resource is updated. @@ -326,7 +338,7 @@ class Chef resources = [resources].flatten resources.each do |resource| if resource.is_a?(String) - resource = Chef::Resource.new(resource, run_context) + resource = UnresolvedSubscribes.new(resource, run_context) end if resource.run_context.nil? resource.run_context = run_context diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb index 89247d46bb..7ef476c44b 100644 --- a/lib/chef/run_context.rb +++ b/lib/chef/run_context.rb @@ -194,6 +194,9 @@ class Chef # @param [Chef::Resource::Notification] The notification to add. # def notifies_before(notification) + # Note for the future, notification.notifying_resource may be an instance + # of Chef::Resource::UnresolvedSubscribes when calling {Resource#subscribes} + # with a string value. before_notification_collection[notification.notifying_resource.declared_key] << notification end @@ -203,6 +206,9 @@ class Chef # @param [Chef::Resource::Notification] The notification to add. # def notifies_immediately(notification) + # Note for the future, notification.notifying_resource may be an instance + # of Chef::Resource::UnresolvedSubscribes when calling {Resource#subscribes} + # with a string value. immediate_notification_collection[notification.notifying_resource.declared_key] << notification end @@ -212,6 +218,9 @@ class Chef # @param [Chef::Resource::Notification] The notification to add. # def notifies_delayed(notification) + # Note for the future, notification.notifying_resource may be an instance + # of Chef::Resource::UnresolvedSubscribes when calling {Resource#subscribes} + # with a string value. delayed_notification_collection[notification.notifying_resource.declared_key] << notification end -- cgit v1.2.1