Module: Spice::Connection::Cookbooks
- Included in:
- Spice, Spice::Connection
- Defined in:
- lib/spice/connection/cookbooks.rb
Instance Method Summary (collapse)
-
- (Spice::Cookbook) cookbook(name)
Retrieve a single cookbook.
-
- (Spice::CookbookVersion) cookbook_version(name, version)
Retrieve a single cookbook version.
-
- (Array<Spice::Cookbook>) cookbooks
Retrieve an array of all cookbooks.
Instance Method Details
- (Spice::Cookbook) cookbook(name)
Retrieve a single cookbook
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 = connection.get("/cookbooks/#{name}").body puts cookbook[name] versions = cookbook[name]['versions'].map{ |v| v['version'] } Spice::Cookbook.new(:name => name, :versions => versions) else connection.get("/cookbooks").body.keys.map do |cookbook| attributes = connection.get("/cookbooks/#{cookbook}").body.to_a[0] Spice::Cookbook.new(:name => attributes[0], :versions => attributes[1]) end end end |
- (Spice::CookbookVersion) cookbook_version(name, version)
Retrieve a single cookbook version
48 49 50 51 |
# File 'lib/spice/connection/cookbooks.rb', line 48 def cookbook_version(name, version) attributes = connection.get("/cookbooks/#{name}/#{version}").body Spice::CookbookVersion.new(attributes) end |
- (Array<Spice::Cookbook>) cookbooks
Retrieve an array of all cookbooks
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 = [] connection.get("/cookbooks").body.each_pair do |key, value| versions = value['versions'].map{ |v| v['version'] } cookbooks << Spice::Cookbook.new(:name => key, :versions => versions) end cookbooks else connection.get("/cookbooks").body.keys.map do |cookbook| attributes = connection.get("/cookbooks/#{cookbook}").body.to_a[0] Spice::Cookbook.new(:name => attributes[0], :versions => attributes[1]) end end end |