summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Black <raskchanky@gmail.com>2014-11-19 15:25:31 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2015-08-18 12:05:30 -0700
commit4c542d34326d7530daeae27fdc0b19f96671291c (patch)
tree67c9403cbb0f27dbe9a8c50031fe6841cc1c7297
parente4586087b54bcd8944436957248cb9fba3757214 (diff)
downloadchef-4c542d34326d7530daeae27fdc0b19f96671291c.tar.gz
add privacy flag
-rw-r--r--lib/chef/cookbook/metadata.rb28
-rw-r--r--spec/unit/cookbook/metadata_spec.rb26
2 files changed, 48 insertions, 6 deletions
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index 01a98fda39..9822920a7d 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -54,12 +54,13 @@ class Chef
VERSION = 'version'.freeze
SOURCE_URL = 'source_url'.freeze
ISSUES_URL = 'issues_url'.freeze
+ PRIVACY = 'privacy'.freeze
COMPARISON_FIELDS = [ :name, :description, :long_description, :maintainer,
:maintainer_email, :license, :platforms, :dependencies,
:recommendations, :suggestions, :conflicting, :providing,
:replacing, :attributes, :groupings, :recipes, :version,
- :source_url, :issues_url ]
+ :source_url, :issues_url, :privacy ]
VERSION_CONSTRAINTS = {:depends => DEPENDENCIES,
:recommends => RECOMMENDATIONS,
@@ -116,6 +117,7 @@ class Chef
@version = Version.new("0.0.0")
@source_url = ''
@issues_url = ''
+ @privacy = false
@errors = []
end
@@ -454,7 +456,8 @@ class Chef
:recipes => { :kind_of => [ Array ], :default => [] },
:default => { :kind_of => [ String, Array, Hash, Symbol, Numeric, TrueClass, FalseClass ] },
:source_url => { :kind_of => String },
- :issues_url => { :kind_of => String }
+ :issues_url => { :kind_of => String },
+ :privacy => { :kind_of => [ TrueClass, FalseClass ] }
}
)
options[:required] = remap_required_attribute(options[:required]) unless options[:required].nil?
@@ -498,7 +501,8 @@ class Chef
RECIPES => self.recipes,
VERSION => self.version,
SOURCE_URL => self.source_url,
- ISSUES_URL => self.issues_url
+ ISSUES_URL => self.issues_url,
+ PRIVACY => self.privacy
}
end
@@ -532,6 +536,7 @@ class Chef
@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)
+ @privacy = o[PRIVACY] if o.has_key?(PRIVACY)
self
end
@@ -590,6 +595,23 @@ class Chef
)
end
+ #
+ # Sets the cookbook's privacy flag, or returns it.
+ #
+ # === Parameters
+ # privacy<TrueClass,FalseClass>:: Whether this cookbook is private or not
+ #
+ # === Returns
+ # privacy<TrueClass,FalseClass>:: Whether this cookbook is private or not
+ #
+ def privacy(arg=nil)
+ set_or_return(
+ :privacy,
+ arg,
+ :kind_of => [ TrueClass, FalseClass ]
+ )
+ end
+
private
def run_validation
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb
index d2954726e8..1b30286f51 100644
--- a/spec/unit/cookbook/metadata_spec.rb
+++ b/spec/unit/cookbook/metadata_spec.rb
@@ -30,7 +30,7 @@ describe Chef::Cookbook::Metadata do
:maintainer_email, :license, :platforms, :dependencies,
:recommendations, :suggestions, :conflicting, :providing,
:replacing, :attributes, :groupings, :recipes, :version,
- :source_url, :issues_url ]
+ :source_url, :issues_url, :privacy ]
end
it "does not depend on object identity for equality" do
@@ -148,6 +148,10 @@ describe Chef::Cookbook::Metadata do
it "has an empty issues_url string" do
expect(metadata.issues_url).to eq('')
end
+
+ it "is not private" do
+ expect(metadata.privacy).to eq(false)
+ end
end
describe "validation" do
@@ -198,7 +202,8 @@ describe Chef::Cookbook::Metadata do
:long_description => "Much Longer\nSeriously",
:version => "0.6.0",
:source_url => "http://example.com",
- :issues_url => "http://example.com/issues"
+ :issues_url => "http://example.com/issues",
+ :privacy => true
}
params.sort { |a,b| a.to_s <=> b.to_s }.each do |field, field_value|
describe field do
@@ -360,7 +365,8 @@ describe Chef::Cookbook::Metadata do
"recipes" => [ "mysql::server", "mysql::master" ],
"default" => [ ],
"source_url" => "http://example.com",
- "issues_url" => "http://example.com/issues"
+ "issues_url" => "http://example.com/issues",
+ "privacy" => true
}
expect(metadata.attribute("/db/mysql/databases", attrs)).to eq(attrs)
end
@@ -401,6 +407,18 @@ describe Chef::Cookbook::Metadata do
}.to raise_error(ArgumentError)
end
+ it "should not accept anything but true or false for the privacy flag" do
+ expect {
+ metadata.attribute("db/mysql/databases", :privacy => true)
+ }.not_to raise_error
+ expect {
+ metadata.attribute("db/mysql/databases", :privacy => false)
+ }.not_to raise_error
+ expect {
+ metadata.attribute("db/mysql/databases", :privacy => 'true')
+ }.to raise_error(ArgumentError)
+ end
+
it "should not accept anything but an array of strings for choice" do
expect {
metadata.attribute("db/mysql/databases", :choice => ['dedicated', 'shared'])
@@ -699,6 +717,7 @@ describe Chef::Cookbook::Metadata do
version
source_url
issues_url
+ privacy
}.each do |t|
it "should include '#{t}'" do
expect(deserialized_metadata[t]).to eq(metadata.send(t.to_sym))
@@ -734,6 +753,7 @@ describe Chef::Cookbook::Metadata do
version
source_url
issues_url
+ privacy
}.each do |t|
it "should match '#{t}'" do
expect(deserialized_metadata.send(t.to_sym)).to eq(metadata.send(t.to_sym))