Class: Ridley::Chef::Cookbook::Metadata
- Inherits:
-
Object
- Object
- Ridley::Chef::Cookbook::Metadata
- Includes:
- Mixin::FromFile, Mixin::ParamsValidate
- Defined in:
- lib/ridley/chef/cookbook/metadata.rb
Overview
Borrowed and modified from: https://raw.github.com/opscode/chef/11.4.0/lib/chef/cookbook/metadata.rb
- Copyright
-
Copyright 2008-2010 Opscode, Inc.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Chef::Cookbook::Metadata
Chef::Cookbook::Metadata provides a convenient DSL for declaring metadata about Chef Cookbooks.
Direct Known Subclasses
Constant Summary collapse
- 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
- PRIVACY =
"privacy".freeze
- CHEF_VERSIONS =
"chef_versions".freeze
- OHAI_VERSIONS =
"ohai_versions".freeze
- GEMS =
"gems".freeze
- COMPILED_FILE_NAME =
"metadata.json".freeze
- RAW_FILE_NAME =
"metadata.rb".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, :privacy, :chef_versions, :ohai_versions, :gems ]
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#chef_versions ⇒ Array<Gem::Dependency>
readonly
Array of supported Chef versions.
-
#conflicting ⇒ Object
readonly
Returns the value of attribute conflicting.
-
#cookbook ⇒ Object
readonly
Returns the value of attribute cookbook.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#gems ⇒ Array<Array>
readonly
Array of gems to install with *args as an Array.
-
#groupings ⇒ Object
readonly
Returns the value of attribute groupings.
-
#ohai_versions ⇒ Array<Gem::Dependency>
readonly
Array of supported Ohai versions.
-
#platforms ⇒ Object
readonly
Returns the value of attribute platforms.
-
#providing ⇒ Object
readonly
Returns the value of attribute providing.
-
#recipes ⇒ Object
readonly
Returns the value of attribute recipes.
-
#recommendations ⇒ Object
readonly
Returns the value of attribute recommendations.
-
#replacing ⇒ Object
readonly
Returns the value of attribute replacing.
-
#suggestions ⇒ Object
readonly
Returns the value of attribute suggestions.
-
#version(arg = nil) ⇒ Object
readonly
Sets the current cookbook version, or returns it.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#attribute(name, options) ⇒ Object
Adds an attribute )hat a user needs to configure for this cookbook.
-
#chef_version(*version_args) ⇒ Array<Gem::Dependency>
Metadata DSL to set a valid chef_version.
-
#conflicts(cookbook, *version_args) ⇒ Object
Adds a conflict for another cookbook, with version checking strings.
-
#depends(cookbook, *version_args) ⇒ Object
Adds a dependency on another cookbook, with version checking strings.
-
#description(arg = nil) ⇒ Object
Sets the current description, or returns it.
- #from_hash(o) ⇒ Object
- #from_json(json) ⇒ Object
-
#gem(*args) ⇒ Array<Array>
Metadata DSL to set a gem to install from the cookbook metadata.
-
#gem_requirements_from_array(what, array) ⇒ Array<Gem::Dependency>
Convert an Array of Gem::Dependency objects (chef_version/ohai_version) to a hash.
-
#gem_requirements_to_array(*deps) ⇒ Array<Array<String>]
Convert an Array of Gem::Dependency objects (chef_version/ohai_version) to an Array.
- #grouping(name, options) ⇒ Object
-
#initialize(cookbook = nil, maintainer = 'YOUR_COMPANY_NAME', maintainer_email = 'YOUR_EMAIL', license = 'none') ⇒ Metadata
constructor
Builds a new Chef::Cookbook::Metadata object.
-
#issues_url(arg = nil) ⇒ Object
Sets the cookbook’s issues URL, or returns it.
-
#license(arg = nil) ⇒ Object
Sets the current license, or returns it.
-
#long_description(arg = nil) ⇒ Object
Sets the current long description, or returns it.
-
#maintainer(arg = nil) ⇒ Object
Sets the cookbooks maintainer, or returns it.
-
#maintainer_email(arg = nil) ⇒ Object
Sets the maintainers email address, or returns it.
-
#method_missing(method_sym, *args) ⇒ Object
Ensure that we don’t have to update Ridley every time we add a new metadata field to Chef.
-
#name(arg = nil) ⇒ Object
Sets the name of the cookbook, or returns it.
-
#ohai_version(*version_args) ⇒ Array<Gem::Dependency>
Metadata DSL to set a valid ohai_version.
-
#privacy(arg = nil) ⇒ Object
Sets the cookbook’s privacy flag, or returns it.
-
#provides(cookbook, *version_args) ⇒ Object
Adds a recipe, definition, or resource provided by this cookbook.
-
#recipe(name, description) ⇒ Object
Adds a description for a recipe.
-
#recommends(cookbook, *version_args) ⇒ Object
Adds a recommendation for another cookbook, with version checking strings.
-
#replaces(cookbook, *version_args) ⇒ Object
Adds a cookbook that is replaced by this one, with version checking strings.
-
#source_url(arg = nil) ⇒ Object
Sets the cookbook’s source URL, or returns it.
-
#suggests(cookbook, *version_args) ⇒ Object
Adds a suggestion for another cookbook, with version checking strings.
-
#supports(platform, *version_args) ⇒ Object
Adds a supported platform, with version checking strings.
- #to_hash ⇒ Object
- #to_json ⇒ String
Methods included from Mixin::FromFile
#class_from_file, #from_file, included
Methods included from Mixin::ParamsValidate
Constructor Details
#initialize(cookbook = nil, maintainer = 'YOUR_COMPANY_NAME', maintainer_email = 'YOUR_EMAIL', license = 'none') ⇒ Metadata
Builds a new Chef::Cookbook::Metadata object.
Parameters
- cookbook<String>
-
An optional cookbook object
- maintainer<String>
-
An optional maintainer
- maintainer_email<String>
-
An optional maintainer email
license<String>::An optional license. Default is Apache v2.0
Returns
metadata<Chef::Cookbook::Metadata>
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 101 def initialize(cookbook = nil, maintainer = 'YOUR_COMPANY_NAME', maintainer_email = 'YOUR_EMAIL', license = 'none') @cookbook = cookbook @name = cookbook ? cookbook.name : "" @long_description = "" self.maintainer(maintainer) self.maintainer_email(maintainer_email) self.license(license) self.description('A fabulous new cookbook') @platforms = Hashie::Mash.new @dependencies = Hashie::Mash.new @recommendations = Hashie::Mash.new @suggestions = Hashie::Mash.new @conflicting = Hashie::Mash.new @providing = Hashie::Mash.new @replacing = Hashie::Mash.new @attributes = Hashie::Mash.new @groupings = Hashie::Mash.new @recipes = Hashie::Mash.new @version = Semverse::Version.new("0.0.0") @source_url = '' @issues_url = '' @privacy = false @chef_versions = [] @ohai_versions = [] @gems = [] if cookbook @recipes = cookbook.fully_qualified_recipe_names.inject({}) do |r, e| e = self.name if e =~ /::default$/ r[e] = "" self.provides e r end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
79 80 81 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 79 def attributes @attributes end |
#chef_versions ⇒ Array<Gem::Dependency> (readonly)
Returns Array of supported Chef versions.
85 86 87 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 85 def chef_versions @chef_versions end |
#conflicting ⇒ Object (readonly)
Returns the value of attribute conflicting.
76 77 78 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 76 def conflicting @conflicting end |
#cookbook ⇒ Object (readonly)
Returns the value of attribute cookbook.
71 72 73 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 71 def cookbook @cookbook end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
73 74 75 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 73 def dependencies @dependencies end |
#gems ⇒ Array<Array> (readonly)
Returns Array of gems to install with *args as an Array.
89 90 91 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 89 def gems @gems end |
#groupings ⇒ Object (readonly)
Returns the value of attribute groupings.
80 81 82 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 80 def groupings @groupings end |
#ohai_versions ⇒ Array<Gem::Dependency> (readonly)
Returns Array of supported Ohai versions.
87 88 89 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 87 def ohai_versions @ohai_versions end |
#platforms ⇒ Object (readonly)
Returns the value of attribute platforms.
72 73 74 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 72 def platforms @platforms end |
#providing ⇒ Object (readonly)
Returns the value of attribute providing.
77 78 79 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 77 def providing @providing end |
#recipes ⇒ Object (readonly)
Returns the value of attribute recipes.
81 82 83 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 81 def recipes @recipes end |
#recommendations ⇒ Object (readonly)
Returns the value of attribute recommendations.
74 75 76 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 74 def recommendations @recommendations end |
#replacing ⇒ Object (readonly)
Returns the value of attribute replacing.
78 79 80 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 78 def replacing @replacing end |
#suggestions ⇒ Object (readonly)
Returns the value of attribute suggestions.
75 76 77 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 75 def suggestions @suggestions end |
#version(arg = nil) ⇒ Object (readonly)
Sets the current cookbook version, or returns it. Can be two or three digits, seperated by dots. ie: ‘2.1’, ‘1.5.4’ or ‘0.9’.
Parameters
- version<String>
-
The curent version, as a string
Returns
- version<String>
-
Returns the current version
232 233 234 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 232 def version @version end |
Class Method Details
.from_hash(hash) ⇒ Object
24 25 26 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 24 def from_hash(hash) new.from_hash(hash) end |
.from_json(json) ⇒ Object
28 29 30 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 28 def from_json(json) new.from_json(json) end |
Instance Method Details
#==(other) ⇒ Object
137 138 139 140 141 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 137 def ==(other) COMPARISON_FIELDS.inject(true) do |equal_so_far, field| equal_so_far && other.respond_to?(field) && (other.send(field) == send(field)) end end |
#attribute(name, options) ⇒ Object
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
display_name<String>:: What a UI should show for this attribute
description<String>:: A hint as to what this attr is for
choice<Array>:: An array of choices to present to the user.
calculated<Boolean>:: If true, the default value is calculated by the recipe and cannot be displayed.
type<String>:: "string" or "array" - default is "string" ("hash" is supported for backwards compatibility)
required<String>:: Whether this attr is 'required', 'recommended' or 'optional' - default 'optional' (true/false values also supported for backwards compatibility)
recipes<Array>:: An array of recipes which need this attr set.
default<String>,<Array>,<Hash>:: The default value
Parameters
- name<String>
-
The name of the attribute (‘foo’, or ‘apache2/log_dir’)
- options<Hash>
-
The description of the options
Returns
- options<Hash>
-
Returns the current options hash
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 434 def attribute(name, ) validate( , { :display_name => { :kind_of => String }, :description => { :kind_of => String }, :choice => { :kind_of => [ Array ], :default => [] }, :calculated => { :equal_to => [ true, false ], :default => false }, :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 ] }, :source_url => { :kind_of => String }, :issues_url => { :kind_of => String }, :privacy => { :kind_of => [ TrueClass, FalseClass ] }, } ) [:required] = remap_required_attribute([:required]) unless [:required].nil? validate_choice_array() validate_calculated_default_rule() validate_choice_default_rule() @attributes[name] = @attributes[name] end |
#chef_version(*version_args) ⇒ Array<Gem::Dependency>
Metadata DSL to set a valid chef_version. May be declared multiple times with the result being ‘OR’d such that if any statements match, the version is considered supported. Uses Gem::Requirement for its implementation.
376 377 378 379 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 376 def chef_version(*version_args) @chef_versions << Gem::Dependency.new("chef", *version_args) unless version_args.empty? @chef_versions end |
#conflicts(cookbook, *version_args) ⇒ Object
Adds a conflict for another cookbook, with version checking strings.
Parameters
- cookbook<String>
-
The cookbook
- version<String>
-
A version constraint of the form “OP VERSION”,
where OP is one of < <= = > >= ~> and VERSION has the form x.y.z or x.y.
Returns
- versions<Array>
-
Returns the list of versions for the platform
329 330 331 332 333 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 329 def conflicts(cookbook, *version_args) version = version_args.first @conflicting[cookbook] = Semverse::Constraint.new(version).to_s @conflicting[cookbook] end |
#depends(cookbook, *version_args) ⇒ Object
Adds a dependency on another cookbook, with version checking strings.
Parameters
- cookbook<String>
-
The cookbook
- version<String>
-
A version constraint of the form “OP VERSION”,
where OP is one of < <= = > >= ~> and VERSION has the form x.y.z or x.y.
Returns
- versions<Array>
-
Returns the list of versions for the platform
281 282 283 284 285 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 281 def depends(cookbook, *version_args) version = version_args.first @dependencies[cookbook] = Semverse::Constraint.new(version).to_s @dependencies[cookbook] end |
#description(arg = nil) ⇒ Object
Sets the current description, or returns it. Should be short - one line only!
Parameters
- description<String>
-
The new description
Returns
- description<String>
-
Returns the description
201 202 203 204 205 206 207 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 201 def description(arg = nil) set_or_return( :description, arg, :kind_of => [ String ] ) end |
#from_hash(o) ⇒ Object
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 542 def from_hash(o) @name = o[NAME] if o.has_key?(NAME) @description = o[DESCRIPTION] if o.has_key?(DESCRIPTION) @long_description = o[LONG_DESCRIPTION] if o.has_key?(LONG_DESCRIPTION) @maintainer = o[MAINTAINER] if o.has_key?(MAINTAINER) @maintainer_email = o[MAINTAINER_EMAIL] if o.has_key?(MAINTAINER_EMAIL) @license = o[LICENSE] if o.has_key?(LICENSE) @platforms = handle_deprecated_constraints(o[PLATFORMS]) if o.has_key?(PLATFORMS) @dependencies = handle_deprecated_constraints(o[DEPENDENCIES]) if o.has_key?(DEPENDENCIES) @recommendations = handle_deprecated_constraints(o[RECOMMENDATIONS]) if o.has_key?(RECOMMENDATIONS) @suggestions = handle_deprecated_constraints(o[SUGGESTIONS]) if o.has_key?(SUGGESTIONS) @conflicting = handle_deprecated_constraints(o[CONFLICTING]) if o.has_key?(CONFLICTING) @providing = o[PROVIDING] if o.has_key?(PROVIDING) @replacing = handle_deprecated_constraints(o[REPLACING]) if o.has_key?(REPLACING) @attributes = o[ATTRIBUTES] if o.has_key?(ATTRIBUTES) @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) @privacy = o[PRIVACY] if o.has_key?(PRIVACY) @chef_versions = gem_requirements_from_array("chef", o[CHEF_VERSIONS]) if o.has_key?(CHEF_VERSIONS) @ohai_versions = gem_requirements_from_array("ohai", o[OHAI_VERSIONS]) if o.has_key?(OHAI_VERSIONS) @gems = o[GEMS] if o.has_key?(GEMS) self end |
#from_json(json) ⇒ Object
569 570 571 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 569 def from_json(json) from_hash JSON.parse(json) end |
#gem(*args) ⇒ Array<Array>
Metadata DSL to set a gem to install from the cookbook metadata. May be declared multiple times. All the gems from all the cookbooks are combined into one Gemfile and depsolved together. Uses Bundler’s DSL for its implementation.
398 399 400 401 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 398 def gem(*args) @gems << args unless args.empty? @gems end |
#gem_requirements_from_array(what, array) ⇒ Array<Gem::Dependency>
Convert an Array of Gem::Dependency objects (chef_version/ohai_version) to a hash.
This is the inverse of #gem_requirements_to_array
500 501 502 503 504 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 500 def gem_requirements_from_array(what, array) array.map do |dep| Gem::Dependency.new(what, *dep) end end |
#gem_requirements_to_array(*deps) ⇒ Array<Array<String>]
Convert an Array of Gem::Dependency objects (chef_version/ohai_version) to an Array.
Gem::Dependencey#to_s is not useful, and there is no #to_json defined on it or its component objets, so we have to write our own rendering method.
- Gem::Dependency.new(“>= 12.5”), Gem::Dependency.new(“>= 11.18.0”, “< 12.0”)
-
results in:
- [ “>= 12.5” ], [ “>= 11.18.0”, “< 12.0”
-
]
485 486 487 488 489 490 491 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 485 def gem_requirements_to_array(*deps) deps.map do |dep| dep.requirement.requirements.map do |op, version| "#{op} #{version}" end.sort end end |
#grouping(name, options) ⇒ Object
460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 460 def grouping(name, ) validate( , { :title => { :kind_of => String }, :description => { :kind_of => String } } ) @groupings[name] = @groupings[name] end |
#issues_url(arg = nil) ⇒ Object
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.
595 596 597 598 599 600 601 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 595 def issues_url(arg = nil) set_or_return( :issues_url, arg, :kind_of => [ String ] ) end |
#license(arg = nil) ⇒ Object
Sets the current license, or returns it.
Parameters
- license<String>
-
The current license.
Returns
- license<String>
-
Returns the current license
186 187 188 189 190 191 192 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 186 def license(arg = nil) set_or_return( :license, arg, :kind_of => [ String ] ) end |
#long_description(arg = nil) ⇒ Object
Sets the current long description, or returns it. Might come from a README, say.
Parameters
- long_description<String>
-
The new long description
Returns
- long_description<String>
-
Returns the long description
216 217 218 219 220 221 222 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 216 def long_description(arg = nil) set_or_return( :long_description, arg, :kind_of => [ String ] ) end |
#maintainer(arg = nil) ⇒ Object
Sets the cookbooks maintainer, or returns it.
Parameters
- maintainer<String>
-
The maintainers name
Returns
- maintainer<String>
-
Returns the current maintainer.
156 157 158 159 160 161 162 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 156 def maintainer(arg = nil) set_or_return( :maintainer, arg, :kind_of => [ String ] ) end |
#maintainer_email(arg = nil) ⇒ Object
Sets the maintainers email address, or returns it.
Parameters
- maintainer_email<String>
-
The maintainers email address
Returns
- maintainer_email<String>
-
Returns the current maintainer email.
171 172 173 174 175 176 177 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 171 def maintainer_email(arg = nil) set_or_return( :maintainer_email, arg, :kind_of => [ String ] ) end |
#name(arg = nil) ⇒ Object
Sets the name of the cookbook, or returns it.
Parameters
- name<String>
-
The curent cookbook name.
Returns
- name<String>
-
Returns the current cookbook name.
247 248 249 250 251 252 253 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 247 def name(arg = nil) set_or_return( :name, arg, :kind_of => [ String ] ) end |
#ohai_version(*version_args) ⇒ Array<Gem::Dependency>
Metadata DSL to set a valid ohai_version. May be declared multiple times with the result being ‘OR’d such that if any statements match, the version is considered supported. Uses Gem::Requirement for its implementation.
387 388 389 390 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 387 def ohai_version(*version_args) @ohai_versions << Gem::Dependency.new("ohai", *version_args) unless version_args.empty? @ohai_versions end |
#privacy(arg = nil) ⇒ Object
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
612 613 614 615 616 617 618 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 612 def privacy(arg = nil) set_or_return( :privacy, arg, :kind_of => [ TrueClass, FalseClass ], ) end |
#provides(cookbook, *version_args) ⇒ Object
Adds a recipe, definition, or resource provided by this cookbook.
Recipes are specified as normal Definitions are followed by (), and can include :params for prototyping Resources are the stringified version (service)
Parameters
- recipe, definition, resource<String>
-
The thing we provide
- version<String>
-
A version constraint of the form “OP VERSION”,
where OP is one of < <= = > >= ~> and VERSION has the form x.y.z or x.y.
Returns
- versions<Array>
-
Returns the list of versions for the platform
349 350 351 352 353 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 349 def provides(cookbook, *version_args) version = version_args.first @providing[cookbook] = Semverse::Constraint.new(version).to_s @providing[cookbook] end |
#recipe(name, description) ⇒ Object
Adds a description for a recipe.
Parameters
- recipe<String>
-
The recipe
- description<String>
-
The description of the recipe
Returns
- description<String>
-
Returns the current description
411 412 413 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 411 def recipe(name, description) @recipes[name] = description end |
#recommends(cookbook, *version_args) ⇒ Object
Adds a recommendation for another cookbook, with version checking strings.
Parameters
- cookbook<String>
-
The cookbook
- version<String>
-
A version constraint of the form “OP VERSION”,
where OP is one of < <= = > >= ~> and VERSION has the form x.y.z or x.y.
Returns
- versions<Array>
-
Returns the list of versions for the platform
297 298 299 300 301 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 297 def recommends(cookbook, *version_args) version = version_args.first @recommendations[cookbook] = Semverse::Constraint.new(version).to_s @recommendations[cookbook] end |
#replaces(cookbook, *version_args) ⇒ Object
Adds a cookbook that is replaced by this one, with version checking strings.
Parameters
- cookbook<String>
-
The cookbook we replace
- version<String>
-
A version constraint of the form “OP VERSION”,
where OP is one of < <= = > >= ~> and VERSION has the form x.y.z or x.y.
Returns
- versions<Array>
-
Returns the list of versions for the platform
364 365 366 367 368 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 364 def replaces(cookbook, *version_args) version = version_args.first @replacing[cookbook] = Semverse::Constraint.new(version).to_s @replacing[cookbook] end |
#source_url(arg = nil) ⇒ Object
Sets the cookbook’s source URL, or returns it.
Parameters
- maintainer<String>
-
The source URL
Returns
- source_url<String>
-
Returns the current source URL.
580 581 582 583 584 585 586 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 580 def source_url(arg = nil) set_or_return( :source_url, arg, :kind_of => [ String ] ) end |
#suggests(cookbook, *version_args) ⇒ Object
Adds a suggestion for another cookbook, with version checking strings.
Parameters
- cookbook<String>
-
The cookbook
- version<String>
-
A version constraint of the form “OP VERSION”,
where OP is one of < <= = > >= ~> and VERSION has the formx.y.z or x.y.
Returns
- versions<Array>
-
Returns the list of versions for the platform
313 314 315 316 317 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 313 def suggests(cookbook, *version_args) version = version_args.first @suggestions[cookbook] = Semverse::Constraint.new(version).to_s @suggestions[cookbook] end |
#supports(platform, *version_args) ⇒ Object
Adds a supported platform, with version checking strings.
Parameters
- platform<String>,<Symbol>
-
The platform (like :ubuntu or :mac_os_x)
- version<String>
-
A version constraint of the form “OP VERSION”,
where OP is one of < <= = > >= ~> and VERSION has the form x.y.z or x.y.
Returns
- versions<Array>
-
Returns the list of versions for the platform
265 266 267 268 269 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 265 def supports(platform, *version_args) version = version_args.first @platforms[platform] = Semverse::Constraint.new(version).to_s @platforms[platform] end |
#to_hash ⇒ Object
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 506 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, SOURCE_URL => self.source_url, ISSUES_URL => self.issues_url, PRIVACY => self.privacy, CHEF_VERSIONS => gem_requirements_to_array(*self.chef_versions), OHAI_VERSIONS => gem_requirements_to_array(*self.ohai_versions), GEMS => self.gems, } end |
#to_json ⇒ String
535 536 537 538 539 540 |
# File 'lib/ridley/chef/cookbook/metadata.rb', line 535 def to_json # Switched from fast to pretty generate here # to match `knife cookbook metadata from file` format # See https://github.com/RiotGames/ridley/pull/287 JSON.pretty_generate(to_hash) end |