class Minimart::Mirror::InventoryRequirements

The collection of requirements as defined in the inventory file.

Attributes

raw_cookbooks[R]

@return [Hash<String, Hash>] The cookbooks listed in the inventory file

requirements[R]

Public Class Methods

new(raw_cookbooks) click to toggle source

@param [Hash<String, Hash>] raw_cookbooks The cookbooks listed in the inventory file

# File lib/minimart/mirror/inventory_requirements.rb, line 16
def initialize(raw_cookbooks)
  @raw_cookbooks = raw_cookbooks
  @requirements  = {}

  parse_cookbooks
end

Public Instance Methods

each(&block) click to toggle source

Iterate over the requirements @yield [Minimart::Inventory::BaseRequirement]

# File lib/minimart/mirror/inventory_requirements.rb, line 25
def each(&block)
  requirements.values.flatten.each &block
end
each_with_explicit_location(&block) click to toggle source
# File lib/minimart/mirror/inventory_requirements.rb, line 29
def each_with_explicit_location(&block)
  each do |req|
    block.call(req) if req.explicit_location?
  end
end
version_required?(name, version) click to toggle source

This method will determine whether or not a version of a cookbook resolves a constraint defined in the inventory file. This method can be used to verify that we aren't downloading a non specified version of a cookbook (e.g. possibly downloading cookbooks that a user wants, but in versions that they do not) @param [String] name The name of the cookbook to verify @param [String] version The cookbook version to check @return [Boolean] Return true if this version solves a requirement

as specified in the inventory. This method will also return true for
any cookbooks not specified in the inventory.
# File lib/minimart/mirror/inventory_requirements.rb, line 45
def version_required?(name, version)
  (!has_cookbook?(name)) ||
    solves_explicit_requirement?(name, version)
end

Private Instance Methods

build_requirements_for(name, reqs) click to toggle source
# File lib/minimart/mirror/inventory_requirements.rb, line 73
def build_requirements_for(name, reqs)
  get_requirements_for(name, reqs).tap do |parsed_requirements|
    validate_requirements(name, parsed_requirements)
  end
end
get_requirements_for(name, reqs) click to toggle source
# File lib/minimart/mirror/inventory_requirements.rb, line 79
def get_requirements_for(name, reqs)
  (market_requirements(name, reqs) +
    git_requirements(name, reqs) +
    local_path_requirements(name, reqs)).flatten.compact
end
git_requirements(name, reqs) click to toggle source
# File lib/minimart/mirror/inventory_requirements.rb, line 95
def git_requirements(name, reqs)
  InventoryRequirement::GitRequirementsBuilder.new(name, reqs).build
end
has_cookbook?(name) click to toggle source
# File lib/minimart/mirror/inventory_requirements.rb, line 54
def has_cookbook?(name)
  requirements.has_key?(name)
end
local_path_requirements(name, reqs) click to toggle source
# File lib/minimart/mirror/inventory_requirements.rb, line 99
def local_path_requirements(name, reqs)
  InventoryRequirement::LocalRequirementsBuilder.new(name, reqs).build
end
market_requirements(name, reqs) click to toggle source
# File lib/minimart/mirror/inventory_requirements.rb, line 91
def market_requirements(name, reqs)
  InventoryRequirement::SupermarketRequirementsBuilder.new(name, reqs).build
end
parse_cookbooks() click to toggle source

Build Minimart::Inventory requirements from the inventory.

# File lib/minimart/mirror/inventory_requirements.rb, line 67
def parse_cookbooks
  raw_cookbooks.each do |name, reqs|
    @requirements[name] = build_requirements_for(name, (reqs || {}))
  end
end
solves_explicit_requirement?(name, version) click to toggle source
# File lib/minimart/mirror/inventory_requirements.rb, line 58
def solves_explicit_requirement?(name, version)
  requirements[name].each do |req|
    next unless req.version_requirement?
    return true if Semverse::Constraint.new(req.version_requirement).satisfies?(version)
  end
  return false
end
validate_requirements(name, reqs) click to toggle source
# File lib/minimart/mirror/inventory_requirements.rb, line 85
def validate_requirements(name, reqs)
  return unless reqs.nil? || reqs.empty?
  raise Minimart::Error::InvalidInventoryError,
    "Minimart could not find any requirements for '#{name}'"
end