class Minimart::Mirror::SourceCookbook

A wrapper around a cookbook as found in the universe.json file from an external source (Chef Supermarket, etc…).

Attributes

dependencies[RW]

@return [Hash<String,String>] any dependencies the cookbook has

download_url[RW]

@return [String] URL to download the cookbook

location_path[RW]

@return [String] the path to the cookbook

location_type[RW]

@return [String] the type of location the cookbook is stored in (supermarket, etc.)

name[RW]

@return [String] the name of the cookbook

version[RW]

@return [String] the version of the cookbook

Public Class Methods

new(opts) click to toggle source

@param [Hash] opts @option opts [String] name The name of the cookbook @option opts [String] version The version of the cookbook @option opts [String] location_path The path to the cookbook @option opts [String] download_url URL to download the cookbook @option opts [Hash] dependencies A hash containing any of the cookbook's dependencies. @option opts [String] location_type The type of location the cookbook is stored in (supermarket, etc.)

# File lib/minimart/mirror/source_cookbook.rb, line 35
def initialize(opts)
  @name          = fetch_from_options(opts, 'name')
  @version       = fetch_from_options(opts, 'version')
  @location_path = fetch_from_options(opts, 'location_path')
  @download_url  = fetch_from_options(opts, 'download_url')
  @dependencies  = fetch_from_options(opts, 'dependencies') || {}
  @location_type = fetch_from_options(opts, 'location_type')
end

Public Instance Methods

fetch(&block) click to toggle source

Download this remote cookbook @yield [Dir] The path to the downloaded cookbook. This directory will be removed when the block exits.

# File lib/minimart/mirror/source_cookbook.rb, line 46
def fetch(&block)
  Download::Cookbook.new(self).fetch(&block)
end
location_path_uri() click to toggle source

Get the location_path as a URI @return [URI]

# File lib/minimart/mirror/source_cookbook.rb, line 64
def location_path_uri
  URI.parse(location_path)
end
to_hash() click to toggle source

Convert this remote cookbook to a Hash @return [Hash]

# File lib/minimart/mirror/source_cookbook.rb, line 52
def to_hash
  {
    metadata_version: '2.0',
    name: @name,
    version: @version,
    source_type: location_type,
    location:    location_path
  }
end
web_friendly_version() click to toggle source
# File lib/minimart/mirror/source_cookbook.rb, line 68
def web_friendly_version
  version.gsub('.', '_')
end

Private Instance Methods

fetch_from_options(opts, key) click to toggle source
# File lib/minimart/mirror/source_cookbook.rb, line 74
def fetch_from_options(opts, key)
  opts[key] || opts[key.to_sym]
end