diff options
author | Steven Danna <steve@opscode.com> | 2014-04-09 00:53:55 -0700 |
---|---|---|
committer | Steven Danna <steve@opscode.com> | 2014-04-09 00:53:55 -0700 |
commit | d1fd50c458808ffe13b791b59ede04ca84c033e1 (patch) | |
tree | 106ec5acfe175c1ffdf90ee4b0e30c8ef7e26e42 | |
parent | 11e115cad0279637f37c0c73ebe11535da3623b8 (diff) | |
download | chef-d1fd50c458808ffe13b791b59ede04ca84c033e1.tar.gz |
[CHEF-5163] Support lazy evaluation the mount resource's options attr
set_or_return calls #call on any DelayedEvaluator on read and compares
the results against the parameter validations. This patch adds String
to the evaluation but ensure that someone reading the options value
will only ever get an Array, keeping the original contract.
-rw-r--r-- | chef/lib/chef/resource/mount.rb | 21 | ||||
-rw-r--r-- | chef/spec/unit/resource/mount_spec.rb | 11 |
2 files changed, 22 insertions, 10 deletions
diff --git a/chef/lib/chef/resource/mount.rb b/chef/lib/chef/resource/mount.rb index 8c32bdd280..cf163e368c 100644 --- a/chef/lib/chef/resource/mount.rb +++ b/chef/lib/chef/resource/mount.rb @@ -76,20 +76,21 @@ class Chef :kind_of => [ String ] ) end - + def options(arg=nil) - if arg.is_a?(String) - converted_arg = arg.gsub(/,/, ' ').split(/ /) + ret = set_or_return( + :options, + arg, + :kind_of => [ Array, String ] + ) + if ret.is_a? String + ret.gsub(/,/, ' ').split(/ /) else - converted_arg = arg + ret end - set_or_return( - :options, - converted_arg, - :kind_of => [ Array ] - ) + end - + def dump(arg=nil) set_or_return( :dump, diff --git a/chef/spec/unit/resource/mount_spec.rb b/chef/spec/unit/resource/mount_spec.rb index 498f33a7ba..fe92ed6e27 100644 --- a/chef/spec/unit/resource/mount_spec.rb +++ b/chef/spec/unit/resource/mount_spec.rb @@ -82,6 +82,17 @@ describe Chef::Resource::Mount do @resource.options.should be_a_kind_of(Array) end + it "should allow options to be sent as a delayed evaluator" do + @resource.options Chef::DelayedEvaluator.new {["rw", "noexec"]} + @resource.options.should eql(["rw", "noexec"]) + end + + it "should allow options to be sent as a delayed evaluator, and convert to array" do + @resource.options Chef::DelayedEvaluator.new {"rw,noexec"} + @resource.options.should be_a_kind_of(Array) + @resource.options.should eql(["rw", "noexec"]) + end + it "should accept true for mounted" do @resource.mounted(true) @resource.mounted.should eql(true) |