summaryrefslogtreecommitdiff
path: root/lib/chef/run_context.rb
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-10-15 12:56:41 -0700
committerJohn Keiser <john@johnkeiser.com>2015-12-09 10:26:08 -0800
commit90cddbbfcf5d7524485c41b6f1fccfe6756a7da4 (patch)
treed9bd4eaed6c329ab591c7698b7c56a5cf915bebf /lib/chef/run_context.rb
parent2d915fee09e402bdba8928d28fdc12fa6c37f4c9 (diff)
downloadchef-90cddbbfcf5d7524485c41b6f1fccfe6756a7da4.tar.gz
Add immediately_before notification
Diffstat (limited to 'lib/chef/run_context.rb')
-rw-r--r--lib/chef/run_context.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb
index f7ab88f7e0..b725857bc5 100644
--- a/lib/chef/run_context.rb
+++ b/lib/chef/run_context.rb
@@ -104,6 +104,15 @@ class Chef
#
#
+ # A Hash containing the immediately_before notifications triggered by resources
+ # during the converge phase of the chef run.
+ #
+ # @return [Hash[String, Array[Chef::Resource::Notification]]] A hash from
+ # <notifying resource name> => <list of notifications it sent>
+ #
+ attr_reader :immediately_before_notification_collection
+
+ #
# A Hash containing the immediate notifications triggered by resources
# during the converge phase of the chef run.
#
@@ -164,11 +173,26 @@ class Chef
def initialize_child_state
@audits = {}
@resource_collection = Chef::ResourceCollection.new
+ @immediately_before_notification_collection = Hash.new {|h,k| h[k] = []}
@immediate_notification_collection = Hash.new {|h,k| h[k] = []}
@delayed_notification_collection = Hash.new {|h,k| h[k] = []}
end
#
+ # Adds an immediately_before notification to the +immediately_before_notification_collection+.
+ #
+ # @param [Chef::Resource::Notification] The notification to add.
+ #
+ def notifies_immediately_before(notification)
+ nr = notification.notifying_resource
+ if nr.instance_of?(Chef::Resource)
+ immediately_before_notification_collection[nr.name] << notification
+ else
+ immediately_before_notification_collection[nr.declared_key] << notification
+ end
+ end
+
+ #
# Adds an immediate notification to the +immediate_notification_collection+.
#
# @param [Chef::Resource::Notification] The notification to add.
@@ -197,6 +221,22 @@ class Chef
end
#
+ # Get the list of immediately_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 immediately_before_notifications(resource)
+ if resource.instance_of?(Chef::Resource)
+ return immediately_before_notification_collection[resource.name]
+ else
+ return immediately_before_notification_collection[resource.declared_key]
+ end
+ end
+
+ #
# Get the list of immediate notifications sent by the given resource.
#
# TODO seriously, this is actually wrong. resource.name is not unique,
@@ -608,10 +648,13 @@ ERROR_MESSAGE
immediate_notification_collection
immediate_notification_collection=
immediate_notifications
+ immediately_before_notification_collection
+ immediately_before_notifications
include_recipe
initialize_child_state
load_recipe
load_recipe_file
+ notifies_immediately_before
notifies_immediately
notifies_delayed
parent_run_context