diff options
-rw-r--r-- | lib/chef/cookbook/metadata.rb | 119 | ||||
-rw-r--r-- | spec/unit/cookbook/metadata_spec.rb | 41 |
2 files changed, 118 insertions, 42 deletions
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index 3964354d50..54e930135d 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -35,28 +35,31 @@ class Chef # about Chef Cookbooks. class Metadata - NAME = 'name'.freeze - DESCRIPTION = 'description'.freeze - LONG_DESCRIPTION = 'long_description'.freeze - MAINTAINER = 'maintainer'.freeze - MAINTAINER_EMAIL = 'maintainer_email'.freeze - LICENSE = 'license'.freeze - PLATFORMS = 'platforms'.freeze - DEPENDENCIES = 'dependencies'.freeze - RECOMMENDATIONS = 'recommendations'.freeze - SUGGESTIONS = 'suggestions'.freeze - CONFLICTING = 'conflicting'.freeze - PROVIDING = 'providing'.freeze - REPLACING = 'replacing'.freeze - ATTRIBUTES = 'attributes'.freeze - GROUPINGS = 'groupings'.freeze - RECIPES = 'recipes'.freeze - VERSION = 'version'.freeze + NAME = 'name'.freeze + DESCRIPTION = 'description'.freeze + LONG_DESCRIPTION = 'long_description'.freeze + MAINTAINER = 'maintainer'.freeze + MAINTAINER_EMAIL = 'maintainer_email'.freeze + LICENSE = 'license'.freeze + PLATFORMS = 'platforms'.freeze + DEPENDENCIES = 'dependencies'.freeze + RECOMMENDATIONS = 'recommendations'.freeze + SUGGESTIONS = 'suggestions'.freeze + CONFLICTING = 'conflicting'.freeze + PROVIDING = 'providing'.freeze + REPLACING = 'replacing'.freeze + ATTRIBUTES = 'attributes'.freeze + GROUPINGS = 'groupings'.freeze + RECIPES = 'recipes'.freeze + VERSION = 'version'.freeze + SOURCE_URL = 'source_url'.freeze + ISSUES_URL = 'issues_url'.freeze COMPARISON_FIELDS = [ :name, :description, :long_description, :maintainer, :maintainer_email, :license, :platforms, :dependencies, :recommendations, :suggestions, :conflicting, :providing, - :replacing, :attributes, :groupings, :recipes, :version] + :replacing, :attributes, :groupings, :recipes, :version, + :source_url, :issues_url ] VERSION_CONSTRAINTS = {:depends => DEPENDENCIES, :recommends => RECOMMENDATIONS, @@ -111,6 +114,8 @@ class Chef @groupings = Mash.new @recipes = Mash.new @version = Version.new("0.0.0") + @source_url = '' + @issues_url = '' @errors = [] end @@ -413,7 +418,7 @@ class Chef end end - # Adds an attribute )hat a user needs to configure for this cookbook. Takes + # Adds an attribute that a user needs to configure for this cookbook. Takes # a name (with the / notation for a nested attribute), followed by any of # these options # @@ -443,7 +448,9 @@ class Chef :type => { :equal_to => [ "string", "array", "hash", "symbol", "boolean", "numeric" ], :default => "string" }, :required => { :equal_to => [ "required", "recommended", "optional", true, false ], :default => "optional" }, :recipes => { :kind_of => [ Array ], :default => [] }, - :default => { :kind_of => [ String, Array, Hash, Symbol, Numeric, TrueClass, FalseClass ] } + :default => { :kind_of => [ String, Array, Hash, Symbol, Numeric, TrueClass, FalseClass ] }, + :source_url => { :kind_of => String }, + :issues_url => { :kind_of => String } } ) options[:required] = remap_required_attribute(options[:required]) unless options[:required].nil? @@ -469,23 +476,25 @@ class Chef def to_hash { - NAME => self.name, - DESCRIPTION => self.description, - LONG_DESCRIPTION => self.long_description, - MAINTAINER => self.maintainer, - MAINTAINER_EMAIL => self.maintainer_email, - LICENSE => self.license, - PLATFORMS => self.platforms, - DEPENDENCIES => self.dependencies, - RECOMMENDATIONS => self.recommendations, - SUGGESTIONS => self.suggestions, - CONFLICTING => self.conflicting, - PROVIDING => self.providing, - REPLACING => self.replacing, - ATTRIBUTES => self.attributes, - GROUPINGS => self.groupings, - RECIPES => self.recipes, - VERSION => self.version + NAME => self.name, + DESCRIPTION => self.description, + LONG_DESCRIPTION => self.long_description, + MAINTAINER => self.maintainer, + MAINTAINER_EMAIL => self.maintainer_email, + LICENSE => self.license, + PLATFORMS => self.platforms, + DEPENDENCIES => self.dependencies, + RECOMMENDATIONS => self.recommendations, + SUGGESTIONS => self.suggestions, + CONFLICTING => self.conflicting, + PROVIDING => self.providing, + REPLACING => self.replacing, + ATTRIBUTES => self.attributes, + GROUPINGS => self.groupings, + RECIPES => self.recipes, + VERSION => self.version, + SOURCE_URL => self.source_url, + ISSUES_URL => self.issues_url } end @@ -517,6 +526,8 @@ class Chef @groupings = o[GROUPINGS] if o.has_key?(GROUPINGS) @recipes = o[RECIPES] if o.has_key?(RECIPES) @version = o[VERSION] if o.has_key?(VERSION) + @source_url = o[SOURCE_URL] if o.has_key?(SOURCE_URL) + @issues_url = o[ISSUES_URL] if o.has_key?(ISSUES_URL) self end @@ -531,7 +542,9 @@ class Chef VERSION_CONSTRAINTS.each do |dependency_type, hash_key| if dependency_group = o[hash_key] dependency_group.each do |cb_name, constraints| - metadata.send(method_name, cb_name, *Array(constraints)) + if metadata.respond_to?(method_name) + metadata.public_send(method_name, cb_name, *Array(constraints)) + end end end end @@ -543,6 +556,36 @@ class Chef from_hash(o) end + # Sets the cookbook's source URL, or returns it. + # + # === Parameters + # maintainer<String>:: The source URL + # + # === Returns + # source_url<String>:: Returns the current source URL. + def source_url(arg=nil) + set_or_return( + :source_url, + arg, + :kind_of => [ String ] + ) + end + + # Sets the cookbook's issues URL, or returns it. + # + # === Parameters + # issues_url<String>:: The issues URL + # + # === Returns + # issues_url<String>:: Returns the current issues URL. + def issues_url(arg=nil) + set_or_return( + :issues_url, + arg, + :kind_of => [ String ] + ) + end + private def run_validation diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index 86be0d2390..51814320d4 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -29,7 +29,8 @@ describe Chef::Cookbook::Metadata do @fields = [ :name, :description, :long_description, :maintainer, :maintainer_email, :license, :platforms, :dependencies, :recommendations, :suggestions, :conflicting, :providing, - :replacing, :attributes, :groupings, :recipes, :version] + :replacing, :attributes, :groupings, :recipes, :version, + :source_url, :issues_url ] end it "does not depend on object identity for equality" do @@ -140,6 +141,13 @@ describe Chef::Cookbook::Metadata do metadata.recipes.should eq(Mash.new) end + it "has an empty source_url string" do + metadata.source_url.should eq('') + end + + it "has an empty issues_url string" do + metadata.issues_url.should eq('') + end end describe "validation" do @@ -188,7 +196,9 @@ describe Chef::Cookbook::Metadata do :license => "Apache v2.0", :description => "Foobar!", :long_description => "Much Longer\nSeriously", - :version => "0.6.0" + :version => "0.6.0", + :source_url => "http://example.com", + :issues_url => "http://example.com/issues" } params.sort { |a,b| a.to_s <=> b.to_s }.each do |field, field_value| describe field do @@ -333,7 +343,9 @@ describe Chef::Cookbook::Metadata do "type" => 'string', "required" => 'recommended', "recipes" => [ "mysql::server", "mysql::master" ], - "default" => [ ] + "default" => [ ], + "source_url" => "http://example.com", + "issues_url" => "http://example.com/issues" } metadata.attribute("/db/mysql/databases", attrs).should == attrs end @@ -356,6 +368,24 @@ describe Chef::Cookbook::Metadata do }.should raise_error(ArgumentError) end + it "should not accept anything but a string for the source_url" do + lambda { + metadata.attribute("db/mysql/databases", :source_url => "foo") + }.should_not raise_error + lambda { + metadata.attribute("db/mysql/databases", :source_url => Hash.new) + }.should raise_error(ArgumentError) + end + + it "should not accept anything but a string for the issues_url" do + lambda { + metadata.attribute("db/mysql/databases", :issues_url => "foo") + }.should_not raise_error + lambda { + metadata.attribute("db/mysql/databases", :issues_url => Hash.new) + }.should raise_error(ArgumentError) + end + it "should not accept anything but an array of strings for choice" do lambda { metadata.attribute("db/mysql/databases", :choice => ['dedicated', 'shared']) @@ -652,6 +682,8 @@ describe Chef::Cookbook::Metadata do attributes recipes version + source_url + issues_url }.each do |t| it "should include '#{t}'" do deserialized_metadata[t].should == metadata.send(t.to_sym) @@ -685,6 +717,8 @@ describe Chef::Cookbook::Metadata do attributes recipes version + source_url + issues_url }.each do |t| it "should match '#{t}'" do deserialized_metadata.send(t.to_sym).should == metadata.send(t.to_sym) @@ -735,5 +769,4 @@ describe Chef::Cookbook::Metadata do end end - end |