diff options
Diffstat (limited to 'lib/chef/cookbook/metadata.rb')
-rw-r--r-- | lib/chef/cookbook/metadata.rb | 35 |
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 |