summaryrefslogtreecommitdiff
path: root/lib/chef/resource.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/resource.rb
parent2d915fee09e402bdba8928d28fdc12fa6c37f4c9 (diff)
downloadchef-90cddbbfcf5d7524485c41b6f1fccfe6756a7da4.tar.gz
Add immediately_before notification
Diffstat (limited to 'lib/chef/resource.rb')
-rw-r--r--lib/chef/resource.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 43fc1f997d..634d00feef 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -209,6 +209,8 @@ class Chef
# actions have been run. This is the default.
# - `immediate`, `immediately`: Will run the action on the other resource
# immediately (before any other action is run).
+ # - `immediately_before`: Will run the action on the other resource
+ # immediately *before* the action is actually run.
#
# @example Resource by string
# file '/foo.txt' do
@@ -251,9 +253,11 @@ class Chef
notifies_delayed(action, resource)
when 'immediate', 'immediately'
notifies_immediately(action, resource)
+ when 'immediately_before'
+ notifies_immediately_before(action, resource)
else
raise ArgumentError, "invalid timing: #{timing} for notifies(#{action}, #{resources.inspect}, #{timing}) resource #{self} "\
- "Valid timings are: :delayed, :immediate, :immediately"
+ "Valid timings are: :delayed, :immediate, :immediately, :immediately_before"
end
end
@@ -277,6 +281,8 @@ class Chef
# actions have been run. This is the default.
# - `immediate`, `immediately`: The action will run immediately following
# the other resource being updated.
+ # - `immediately_before`: The action will run immediately before the
+ # other resource is updated.
#
# @example Resources by string
# file '/foo.txt' do
@@ -1238,6 +1244,9 @@ class Chef
# resolve_resource_reference on each in turn, causing them to
# resolve lazy/forward references.
def resolve_notification_references
+ run_context.immediately_before_notifications(self).each { |n|
+ n.resolve_resource_reference(run_context.resource_collection)
+ }
run_context.immediate_notifications(self).each { |n|
n.resolve_resource_reference(run_context.resource_collection)
}
@@ -1247,6 +1256,11 @@ class Chef
end
# Helper for #notifies
+ def notifies_immediately_before(action, resource_spec)
+ run_context.notifies_immediately_before(Notification.new(resource_spec, action, self))
+ end
+
+ # Helper for #notifies
def notifies_immediately(action, resource_spec)
run_context.notifies_immediately(Notification.new(resource_spec, action, self))
end
@@ -1341,6 +1355,10 @@ class Chef
"#{declared_type}[#{@name}]"
end
+ def immediately_before_notifications
+ run_context.immediately_before_notifications(self)
+ end
+
def immediate_notifications
run_context.immediate_notifications(self)
end