From 8be4d2a44858b14d10d0a19484a2d090b0a7a2fb Mon Sep 17 00:00:00 2001 From: Serdar Sutay Date: Tue, 14 Oct 2014 14:42:25 -0700 Subject: Differentiate between the default and the user set guard_attributes in order to be able to warn users correctly when they configure a guard_attribute but use a ruby block in the guard. --- lib/chef/resource.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'lib/chef/resource.rb') diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 70abfbcdb0..55de8f059c 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -229,6 +229,8 @@ F attr_reader :elapsed_time + attr_reader :default_guard_interpreter + # Each notify entry is a resource/action pair, modeled as an # Struct with a #resource and #action member @@ -250,7 +252,13 @@ F @not_if = [] @only_if = [] @source_line = nil - @guard_interpreter = :default + # We would like to raise an error when the user gives us a guard + # interpreter and a ruby_block to the guard. In order to achieve this + # we need to understand when the user overrides the default guard + # interpreter. Therefore we store the default separately in a different + # attribute. + @guard_interpreter = nil + @default_guard_interpreter = :default @elapsed_time = 0 @sensitive = false end @@ -410,11 +418,15 @@ F end def guard_interpreter(arg=nil) - set_or_return( - :guard_interpreter, - arg, - :kind_of => Symbol - ) + if arg.nil? + @guard_interpreter || @default_guard_interpreter + else + set_or_return( + :guard_interpreter, + arg, + :kind_of => Symbol + ) + end end # Sets up a notification from this resource to the resource specified by +resource_spec+. -- cgit v1.2.1