summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam Edwards <adamed@opscode.com>2014-03-29 00:20:08 -0700
committerAdam Edwards <adamed@opscode.com>2014-03-29 00:21:14 -0700
commit718de5b01c5458e512004bf072618052ffa654bc (patch)
treef6ebe786d641ad260c399cf776adec8ce6e218a0 /lib
parentbada8aeb8cdac4779a0d65d4d3fd9333910fc886 (diff)
downloadchef-718de5b01c5458e512004bf072618052ffa654bc.tar.gz
CR feedback: clean up convert boolean expressions and add tests
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/guard_interpreter/resource_guard_interpreter.rb11
-rw-r--r--lib/chef/provider/powershell_script.rb2
-rw-r--r--lib/chef/resource/powershell_script.rb18
3 files changed, 22 insertions, 9 deletions
diff --git a/lib/chef/guard_interpreter/resource_guard_interpreter.rb b/lib/chef/guard_interpreter/resource_guard_interpreter.rb
index 0a88d75d5c..c4b6d33a16 100644
--- a/lib/chef/guard_interpreter/resource_guard_interpreter.rb
+++ b/lib/chef/guard_interpreter/resource_guard_interpreter.rb
@@ -24,8 +24,19 @@ class Chef
def translate_command_block(command, opts, &block)
merge_inherited_attributes
+
if command && ! block_given?
block_attributes = opts.merge({:code => command})
+
+ # Handles cases like powershell_script where default
+ # attributes are different when used in a guard vs. not. For
+ # powershell_script in particular, this will go away when
+ # the one attribue that causes this changes its default to be
+ # the same after some period to prepare for deprecation
+ if @resource.class.respond_to?(:get_default_attributes)
+ block_attributes = @resource.class.send(:get_default_attributes, opts).merge(block_attributes)
+ end
+
translated_block = to_block(block_attributes)
[nil, translated_block]
else
diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb
index a5820eb3a2..f3135f1a35 100644
--- a/lib/chef/provider/powershell_script.rb
+++ b/lib/chef/provider/powershell_script.rb
@@ -42,7 +42,7 @@ class Chef
"\n" +
code.to_s +
EXIT_STATUS_NORMALIZATION_SCRIPT )
- convert_boolean_return = @new_resource.convert_boolean_return.nil? ? false : @new_resource.convert_boolean_return
+ convert_boolean_return = @new_resource.convert_boolean_return
@code = <<EOH
new-variable -name interpolatedexitcode -visibility private -value #{convert_boolean_return}
new-variable -name chefscriptresult -visibility private
diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb
index 08568b6964..f053d0b2aa 100644
--- a/lib/chef/resource/powershell_script.rb
+++ b/lib/chef/resource/powershell_script.rb
@@ -36,16 +36,18 @@ class Chef
)
end
- def only_if(command=nil, opts={}, &block)
- augmented_opts = opts.merge((guard_interpreter.nil? || guard_interpreter == :default) ? {} : {:convert_boolean_return => true}) {|key, original_value, augmented_value| original_value}
- super(command, augmented_opts, &block)
- end
+ protected
- def not_if(command=nil, opts={}, &block)
- augmented_opts = opts.merge((guard_interpreter.nil? || guard_interpreter == :default) ? {} : {:convert_boolean_return => true}) {|key, original_value, augmented_value| original_value}
- super(command, augmented_opts, &block)
+ # Allow callers evaluating guards to request default
+ # attribute values. This is needed to allow
+ # convert_boolean_return to be true in guard context by default,
+ # and false by default otherwise. When this mode becomes the
+ # default for this resource, this method can be removed since
+ # guard context and recipe resource context will have the
+ # same behavior.
+ def self.get_default_attributes(opts)
+ {:convert_boolean_return => true}
end
-
end
end
end