Fixed.
The fix provides the ability to notify different resources for different actions.
The new "notifies" method in resources.rb can either be used as the usual way (take 2 or 3 parameters), or take an array of hashes (of resources and actions). For the array of hashes, each element of the array is a hash with the resources as the key, and an array of 2 elements: action and timing as the value.
Basically the syntax is like the following:
notifies ( [ {resources("execute[something]") => [:action, :timing]},
{resources("execute[something]") => [:action, :timing]},
{resources("execute[something]") => [:action, :timing]} ] )
For example:
execute "echo foo" do
notifies([{resources("file#{node[:tmpdir]}/notified_file_2.txt") => [:create, :delayed]},
{resources("file#{node[:tmpdir]}/notified_file_3.txt") => [:create, :delayed]}])
end
-----------
Files changed:
modified: chef/lib/chef/resource.rb
new file: features/data/cookbooks/delayed_notifications/recipes/notify_different_resources_for_different_actions.rb
modified: features/delayed_notifications.feature
Details:
resource.rb -
Changed the original notifies(action, resources, timing = :delayed) method to a private helper method notifies_helper(action, resources, timing=:delayed).
Added new notifies(*args) method:
1. raise ArgumentError if number of arguments passed in is greater than 3 or less than 1.
2. if the number of arguments is greater than 1 (and lass than 4), call the (original) notifies_helper method.
3. if the number of arguments is 1, it's an array of hashes. Process the hashes one by one and call the original notifies_helper method.
notify_different_resources_for_different_actions.rb - the recipe created for testing purpose
delayed_notifications.feature - Added Scenario: Notify different resources for different actions
I like that, but I'd suggest you accept an array as well so that the order is represented, or allow multiple notifies to be used in the same resource.