summaryrefslogtreecommitdiff
path: root/lib/chef/cookbook/metadata.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2014-08-05 13:28:43 -0700
committerdanielsdeleo <dan@getchef.com>2014-08-12 11:03:09 -0700
commitf5ea885549b840cbb9008f739d1f6f1784e06f97 (patch)
tree2ba9660390029cd6beadc1e79707c59e411c2b41 /lib/chef/cookbook/metadata.rb
parent98967ebcf02fa3a85f63a532ca5a43ce70dcfe6a (diff)
downloadchef-f5ea885549b840cbb9008f739d1f6f1784e06f97.tar.gz
Respect metadata name attribute
Fixes CHEF-3307
Diffstat (limited to 'lib/chef/cookbook/metadata.rb')
-rw-r--r--lib/chef/cookbook/metadata.rb35
1 files changed, 28 insertions, 7 deletions
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index 8d3f8b84aa..c7e542e44b 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -92,7 +92,7 @@ class Chef
# metadata<Chef::Cookbook::Metadata>
def initialize(cookbook=nil, maintainer='YOUR_COMPANY_NAME', maintainer_email='YOUR_EMAIL', license='none')
@cookbook = cookbook
- @name = cookbook ? cookbook.name : ""
+ @name = cookbook ? cookbook.name : nil
@long_description = ""
self.maintainer(maintainer)
self.maintainer_email(maintainer_email)
@@ -110,12 +110,7 @@ class Chef
@recipes = Mash.new
@version = Version.new "0.0.0"
if cookbook
- @recipes = cookbook.fully_qualified_recipe_names.inject({}) do |r, e|
- e = self.name.to_s if e =~ /::default$/
- r[e] ||= ""
- self.provides e
- r
- end
+ recipes_from_cookbook_version(cookbook)
end
end
@@ -365,6 +360,32 @@ class Chef
@recipes[name] = description
end
+ # Sets the cookbook's recipes to the list of recipes in the given
+ # +cookbook+. Any recipe that already has a description (if set by the
+ # #recipe method) will not be updated.
+ #
+ # === Parameters
+ # cookbook<CookbookVersion>:: CookbookVersion object representing the cookbook
+ # description<String>:: The description of the recipe
+ #
+ # === Returns
+ # recipe_unqualified_names<Array>:: An array of the recipe names given by the cookbook
+ def recipes_from_cookbook_version(cookbook)
+ cookbook.fully_qualified_recipe_names.map do |recipe_name|
+ unqualified_name =
+ if recipe_name =~ /::default$/
+ self.name.to_s
+ else
+ recipe_name
+ end
+
+ @recipes[unqualified_name] ||= ""
+ provides(unqualified_name)
+
+ unqualified_name
+ end
+ end
+
# Adds an attribute )hat a user needs to configure for this cookbook. Takes
# a name (with the / notation for a nested attribute), followed by any of
# these options