class Minimart::Mirror::Source

Source represents a single remote source to fetch cookbooks from. Each source is specified in the inventory using the 'sources' key.

Attributes

base_url[RW]

@return [String] The URL for this source

Public Class Methods

new(base_url) click to toggle source

@param [String] base_url The URL for this source

# File lib/minimart/mirror/source.rb, line 14
def initialize(base_url)
  @base_url = base_url
end

Public Instance Methods

cookbooks() click to toggle source

Query this source for it's available cookbooks using the '/universe' endpoint. @return [Array<Minimart::Mirror::SourceCookbook]

# File lib/minimart/mirror/source.rb, line 29
def cookbooks
  @cookbooks ||= fetch_universe_data.each_with_object([]) do |cookbook_info, memo|
    name, versions = cookbook_info
    memo.concat versions.map { |version, attrs| build_cookbook(name, version, attrs) }
  end
end
find_cookbook(cookbook_name, version) click to toggle source

Search through the cookbooks available at this source, and return the relevant version if it is available. @return [Minimart::Mirror::SourceCookbook]

# File lib/minimart/mirror/source.rb, line 21
def find_cookbook(cookbook_name, version)
  cookbooks.find do |cookbook|
    cookbook.name == cookbook_name && cookbook.version == version
  end
end
to_s() click to toggle source
# File lib/minimart/mirror/source.rb, line 36
def to_s
  base_url
end

Private Instance Methods

build_cookbook(name, version, attrs) click to toggle source
# File lib/minimart/mirror/source.rb, line 42
def build_cookbook(name, version, attrs)
  attrs = attrs.merge(name: name, version: version)
  SourceCookbook.new(attrs)
end
fetch_universe_data() click to toggle source
# File lib/minimart/mirror/source.rb, line 47
def fetch_universe_data
  Configuration.output.puts "Fetching the universe for #{base_url} ..."

  Utils::Http.get_json(base_url, 'universe')

rescue RestClient::ResourceNotFound
  raise Error::UniverseNotFoundError.new "no universe found for #{base_url}"
end