Module: Spice::Connection::Cookbooks

Included in:
Spice::Connection
Defined in:
lib/spice/connection/cookbooks.rb

Instance Method Summary collapse

Instance Method Details

#cookbook(name) ⇒ Spice::Cookbook

Retrieve a single cookbook

Parameters:

  • name (String)

    The name of the cookbook

Returns:

Raises:


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/spice/connection/cookbooks.rb', line 28

def cookbook(name)
  if Gem::Version.new(Spice.chef_version) >= Gem::Version.new("0.10.0")
    cookbook = get("/cookbooks/#{name}")
    versions = cookbook[name]['versions'].map{ |v| v['version'] }

    Spice::Cookbook.get_or_new(:name => name, :versions => versions)
  else
    cookbook = get("/cookbooks/#{name}")
    Spice::Cookbook.get_or_new(:name => name, :versions => cookbook[name])
  end
end

#cookbook_version(name, version) ⇒ Spice::CookbookVersion

Retrieve a single cookbook version

Parameters:

  • name (String)

    The cookbook name

  • version (String)

    The cookbook version

Returns:

Raises:


45
46
47
48
49
50
# File 'lib/spice/connection/cookbooks.rb', line 45

def cookbook_version(name, version)
  attributes = get("/cookbooks/#{name}/#{version}")
  duped_attributes = attributes.dup
  duped_attributes[:_attributes] = attributes['attributes']
  Spice::CookbookVersion.get_or_new(duped_attributes)
end

#cookbooksArray<Spice::Cookbook>

Retrieve an array of all cookbooks

Examples:

Retrieve all cookbooks with versions

Spice.cookbooks

Returns:


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/spice/connection/cookbooks.rb', line 8

def cookbooks
  if Gem::Version.new(Spice.chef_version) >= Gem::Version.new("0.10.0")
    cookbooks = []
    get("/cookbooks?num_versions=all").each_pair do |key, value|
      versions = value['versions'].map{ |v| v['version'] }
      cookbooks << Spice::Cookbook.get_or_new(:name => key, :versions => versions)
    end
    cookbooks
  else
    get("/cookbooks").keys.map do |cookbook|
      cb = get("/cookbooks/#{cookbook}")
      Spice::Cookbook.get_or_new(:name => cookbook, :versions => cb[cookbook])
    end
  end
end

#delete_cookbook_version(name, version) ⇒ Object

def cookbook_version


52
53
54
55
# File 'lib/spice/connection/cookbooks.rb', line 52

def delete_cookbook_version(name, version)
  delete("/cookbooks/#{name}/#{version}")
  nil
end