summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-03-04 20:28:07 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2015-03-20 14:38:04 -0700
commit4d3b0e6e37bfbc5e1e1c79621b7e311784bb6490 (patch)
tree80f9580e4f728b3011d34d1bf3e82b434ec755a6
parentbf1acd692f204ccae18a0c236469beb56554e669 (diff)
downloadchef-4d3b0e6e37bfbc5e1e1c79621b7e311784bb6490.tar.gz
Added type coercsion for array
-rw-r--r--lib/chef/mixin/powershell_type_coercions.rb10
-rw-r--r--spec/unit/mixin/powershell_type_coercions_spec.rb4
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/chef/mixin/powershell_type_coercions.rb b/lib/chef/mixin/powershell_type_coercions.rb
index c5c035bb7c..1f216176c1 100644
--- a/lib/chef/mixin/powershell_type_coercions.rb
+++ b/lib/chef/mixin/powershell_type_coercions.rb
@@ -26,7 +26,8 @@ class Chef
Float => { :type => lambda { |x| x.to_s }, :single_quoted => false },
FalseClass => { :type => lambda { |x| '$false' }, :single_quoted => false },
TrueClass => { :type => lambda { |x| '$true' }, :single_quoted => false },
- Hash => {:type => Proc.new { |x| translate_hash(x)}, :single_quoted => false}
+ Hash => {:type => Proc.new { |x| translate_hash(x)}, :single_quoted => false},
+ Array => {:type => Proc.new { |x| translate_array(x)}, :single_quoted => false}
}
end
@@ -37,6 +38,13 @@ class Chef
"@{#{translated.join(';')}}"
end
+ def translate_array(x)
+ translated = x.map do |v|
+ translate_type(v)
+ end
+ "@(#{translated.join(',')})"
+ end
+
def translate_type(value)
translation = type_coercions[value.class]
translated_value = nil
diff --git a/spec/unit/mixin/powershell_type_coercions_spec.rb b/spec/unit/mixin/powershell_type_coercions_spec.rb
index a6b944adda..0019c9b74e 100644
--- a/spec/unit/mixin/powershell_type_coercions_spec.rb
+++ b/spec/unit/mixin/powershell_type_coercions_spec.rb
@@ -48,6 +48,10 @@ describe Chef::Mixin::PowershellTypeCoercions do
})).to eq("@{a=1;b=1.2;c=$false;d=$true}")
end
+ it 'should translat all members of an array and them by a ,' do
+ expect(test_class.translate_type([true, false])).to eq('@($true,$false)')
+ end
+
it 'should fall back :to_psobject if we have not defined at explicit rule' do
ps_obj = double("PSObject")
expect(ps_obj).to receive(:to_psobject).and_return('$true')