Class: Chef::MinimalCookbookVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/chef/cookbook_version.rb

Overview

Chef::MinimalCookbookVersion

MinimalCookbookVersion is a duck type of CookbookVersion, used internally by Chef Server as an optimization when determining the optimal cookbook set for a chef-client.

MinimalCookbookVersion objects contain only enough information to solve the cookbook collection for a given run list. They *do not* contain enough information to generate the response.

See also: Chef::CookbookVersionSelector

Constant Summary collapse

ID =
"id".freeze
NAME =
'name'.freeze
KEY =
'key'.freeze
VERSION =
'version'.freeze
VALUE =
'value'.freeze
DEPS =
'deps'.freeze
DEPENDENCIES =
'dependencies'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ MinimalCookbookVersion

Returns a new instance of MinimalCookbookVersion.


82
83
84
85
86
87
# File 'lib/chef/cookbook_version.rb', line 82

def initialize(params)
  @couchdb_id = params[ID]
  @name = params[KEY]
  @version = params[VALUE][VERSION]
  @deps    = params[VALUE][DEPS]
end

Instance Attribute Details

#couchdb_idObject (readonly)

Returns the value of attribute couchdb_id


77
78
79
# File 'lib/chef/cookbook_version.rb', line 77

def couchdb_id
  @couchdb_id
end

#depsObject (readonly)

Returns the value of attribute deps


80
81
82
# File 'lib/chef/cookbook_version.rb', line 80

def deps
  @deps
end

#nameObject (readonly)

Returns the value of attribute name


78
79
80
# File 'lib/chef/cookbook_version.rb', line 78

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version


79
80
81
# File 'lib/chef/cookbook_version.rb', line 79

def version
  @version
end

Class Method Details

.load_all(couchdb) ⇒ Object

Loads the full list of cookbooks, using a couchdb view to fetch only the id, name, version, and dependency constraints. This is enough information to solve for the cookbook collection for a given run list. After solving for the cookbook collection, you need to call load_full_versions_of to convert MinimalCookbookVersion objects to their non-minimal counterparts


62
63
64
65
66
67
# File 'lib/chef/cookbook_version.rb', line 62

def self.load_all(couchdb)
  # Example:
  # {"id"=>"1a806f1c-b409-4d8e-abab-fa414ff5b96d", "key"=>"activemq", "value"=>{"version"=>"0.3.3", "deps"=>{"java"=>">= 0.0.0", "runit"=>">= 0.0.0"}}}
  couchdb ||= Chef::CouchDB.new
  couchdb.get_view("cookbooks", "all_with_version_and_deps")["rows"].map {|params| self.new(params) }
end

.load_full_versions_of(minimal_cookbook_versions, couchdb) ⇒ Object

Loads the non-minimal CookbookVersion objects corresponding to minimal_cookbook_versions from couchdb using a bulk GET.


71
72
73
74
75
# File 'lib/chef/cookbook_version.rb', line 71

def self.load_full_versions_of(minimal_cookbook_versions, couchdb)
  database_ids = Array(minimal_cookbook_versions).map {|mcv| mcv.couchdb_id }
  couchdb ||= Chef::CouchDB.new
  couchdb.bulk_get(*database_ids)
end

Instance Method Details

#<=>(o) ⇒ Object


99
100
101
102
103
# File 'lib/chef/cookbook_version.rb', line 99

def <=>(o)
  raise Chef::Exceptions::CookbookVersionNameMismatch if self.name != o.name
  raise "Unexpected comparison to #{o}" unless o.respond_to?(:legit_version)
  legit_version <=> o.legit_version
end

#legit_versionObject


95
96
97
# File 'lib/chef/cookbook_version.rb', line 95

def legit_version
  @legit_version ||= Chef::Version.new(@version)
end

#metadataObject

Returns the Cookbook::MinimalMetadata object for this cookbook version.


91
92
93
# File 'lib/chef/cookbook_version.rb', line 91

def 
  @metadata ||= Cookbook::MinimalMetadata.new(@name, DEPENDENCIES => @deps)
end