diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-02-05 11:50:31 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-02-05 11:50:31 -0800 |
commit | d6d4fd8721872a0fbd888678e41ca7f5efab994a (patch) | |
tree | ab86895f2e6c7e4c190cbf7fe3a91a0677ebc362 | |
parent | 2dd178e0929324514a4af28a3ccb51779a5b2d4b (diff) | |
download | chef-d6d4fd8721872a0fbd888678e41ca7f5efab994a.tar.gz |
de-uglify and coerce names to strings
- the constructor was bypassing the setter method and allowing random
objects to be set as names when the intent is to only accept strings.
- failing on non-string objects would be a backwards incompatible
change so the constructor was changed to coerce to a string (this has
come up before with the log resource being passed an object).
- a special case was added for arrays so that the name arg of
multipackage installs looks like:
apt_package[lsof, bc]
instead of:
apt_package[["lsof", "bc"]]
- the special case for the array likely only affects the OnePerson(tm) out
there who is passing an array to a resource (like log) already and using
notifies or subscribes against it. better to xkcd that person
now than to have people start to build notification against the new
multipackage syntax and then have to break a lot more people with
Chef-13.
- this doesn't affect the internals of the multipackge stuff because the
packge_name is set to the value the constructor gets (which is an
array) so that the coercsion to string does not affect provider behavior,
but will get notify/subscribe and other resource collection manipulation
and reporting correct.
-rw-r--r-- | lib/chef/resource.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 5a6f3ec037..a767dbe2d6 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -91,7 +91,7 @@ class Chef # @param run_context The context of the Chef run. Corresponds to #run_context. # def initialize(name, run_context=nil) - @name = name + name(name) @run_context = run_context @noop = nil @before = nil @@ -138,8 +138,11 @@ class Chef # def name(name=nil) if !name.nil? - raise ArgumentError, "name must be a string!" unless name.kind_of?(String) - @name = name + if name.is_a?(Array) + @name = name.join(', ') + else + @name = name.to_s + end end @name end |