summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-02-05 19:39:36 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2015-02-05 19:39:36 -0800
commit738f8c273402a6be4956e3a11e7c30e49c70bde1 (patch)
treec60b6b3eb8927ed8be21072409e695b8bb8684d5 /lib/chef
parent2dd178e0929324514a4af28a3ccb51779a5b2d4b (diff)
parent689b88a0d5ad550abe55c6afb708f32b724d34fe (diff)
downloadchef-738f8c273402a6be4956e3a11e7c30e49c70bde1.tar.gz
Merge pull request #2869 from chef/lcg/array-name-deuglification
Lcg/array name deuglification
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/resource.rb17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 5a6f3ec037..ea220b6c70 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
@@ -133,13 +133,22 @@ class Chef
#
# This is also used in to_s to show the resource name, e.g. `execute[Vitruvius]`.
#
- # @param name [String] The name to set.
+ # This is also used for resource notifications and subscribes in the same manner.
+ #
+ # This will coerce any object into a string via #to_s. Arrays are a special case
+ # so that `package ["foo", "bar"]` becomes package[foo, bar] instead of the more
+ # awkward `package[["foo", "bar"]]` that #to_s would produce.
+ #
+ # @param name [Object] The name to set, typically a String or Array
# @return [String] The name of this Resource.
#
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