diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-10-14 14:42:25 -0700 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-10-16 13:30:24 -0700 |
commit | 8be4d2a44858b14d10d0a19484a2d090b0a7a2fb (patch) | |
tree | fa713587092354c19facbc1423ffab4c6bc2cc8e /lib/chef/resource/conditional.rb | |
parent | 8dd586b1fdbb13705a1a3a5f7f792568cc39e434 (diff) | |
download | chef-8be4d2a44858b14d10d0a19484a2d090b0a7a2fb.tar.gz |
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.
Diffstat (limited to 'lib/chef/resource/conditional.rb')
-rw-r--r-- | lib/chef/resource/conditional.rb | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/lib/chef/resource/conditional.rb b/lib/chef/resource/conditional.rb index 6a987d3086..8960a4d57f 100644 --- a/lib/chef/resource/conditional.rb +++ b/lib/chef/resource/conditional.rb @@ -54,29 +54,25 @@ class Chef end def configure - if @block_given - # If a block is given, we will not interpret the block with a guard interpreter. + case @command + when String + @guard_interpreter = new_guard_interpreter(@parent_resource, @command, @command_opts, &@block) + @block = nil + when nil + # We should have a block if we get here + # Check to see if the user set the guard_interpreter on the parent resource. Note that + # this error will not be raised when using the default_guard_interpreter + if @parent_resource.guard_interpreter != @parent_resource.default_guard_interpreter + msg = "#{@parent_resource.name} was given a guard_interpreter of #{@parent_resource.guard_interpreter}, " + msg << "but not given a command as a string. guard_interpreter does not support blocks (because they just contain ruby)." + raise ArgumentError, msg + end + @guard_interpreter = nil @command, @command_opts = nil, nil else - case @command - when String - @guard_interpreter = new_guard_interpreter(@parent_resource, @command, @command_opts, &@block) - @block = nil - when nil - # We should have a block if we get here - if @parent_resource.guard_interpreter != :default - msg = "#{@parent_resource.name} was given a guard_interpreter of #{@parent_resource.guard_interpreter}, " - msg << "but not given a command as a string. guard_interpreter does not support blocks (because they just contain ruby)." - raise ArgumentError, msg - end - - @guard_interpreter = nil - @command, @command_opts = nil, nil - else - # command was passed, but it wasn't a String - raise ArgumentError, "Invalid only_if/not_if command, expected a string: #{command.inspect} (#{command.class})" - end + # command was passed, but it wasn't a String + raise ArgumentError, "Invalid only_if/not_if command, expected a string: #{command.inspect} (#{command.class})" end end |