class Minimart::Mirror::InventoryRequirements
The collection of requirements as defined in the inventory file.
Attributes
@return [Hash<String, Hash>] The cookbooks listed in the inventory file
Public Class Methods
@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
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
# 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
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
# 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
# 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
# File lib/minimart/mirror/inventory_requirements.rb, line 95 def git_requirements(name, reqs) InventoryRequirement::GitRequirementsBuilder.new(name, reqs).build end
# File lib/minimart/mirror/inventory_requirements.rb, line 54 def has_cookbook?(name) requirements.has_key?(name) end
# File lib/minimart/mirror/inventory_requirements.rb, line 99 def local_path_requirements(name, reqs) InventoryRequirement::LocalRequirementsBuilder.new(name, reqs).build end
# File lib/minimart/mirror/inventory_requirements.rb, line 91 def market_requirements(name, reqs) InventoryRequirement::SupermarketRequirementsBuilder.new(name, reqs).build end
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
# 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
# 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