class Minimart::Mirror::DependencyGraph

A dependency graph for managing any remote cookbooks and their dependencies. This can be used to resolve any requirements found in the inventory file.

Attributes

graph[R]
inventory_requirements[R]

Public Class Methods

new() click to toggle source
# File lib/minimart/mirror/dependency_graph.rb, line 14
def initialize
  @graph = Solve::Graph.new
  @inventory_requirements = []
end

Public Instance Methods

add_artifact(cookbook) click to toggle source

Add an artifact (cookbook), to the graph. @param [Minimart::Mirror::SourceCookbook] cookbook

# File lib/minimart/mirror/dependency_graph.rb, line 21
def add_artifact(cookbook)
  return if source_cookbook_added?(cookbook.name, cookbook.version)

  graph.artifact(cookbook.name, cookbook.version).tap do |artifact|
    if load_dependencies?
      cookbook.dependencies.each do |dependency|
        name, requirements = dependency
        artifact.depends(name, requirements)
      end
    end
  end
end
add_requirement(requirements = {}) click to toggle source

Add a new requirement to be resolved by the graph @param [Hash] requirements (ex. { 'minimart' => '> 0.0.1' })

# File lib/minimart/mirror/dependency_graph.rb, line 51
def add_requirement(requirements = {})
  inventory_requirements.concat(requirements.to_a)
end
find_graph_artifact(cookbook) click to toggle source

Get a cookbook out of the graph. @param [Minimart::Mirror::SourceCookbook] cookbook The cookbook to fetch. @return [Solve::Artifact]

# File lib/minimart/mirror/dependency_graph.rb, line 45
def find_graph_artifact(cookbook)
  graph.find(cookbook.name, cookbook.version)
end
resolved_requirements() click to toggle source

Resolve any requirements against the graph @return [Array] The requirements as resolved by the graph (ex. [['minimart', '0.0.5']]) @raise [Minimart::Error::UnresolvedDependency] Raised when a dependency cannot be resolved

# File lib/minimart/mirror/dependency_graph.rb, line 58
def resolved_requirements
  inventory_requirements.inject([]) do |result, requirement|
    result.concat(resolve_requirement(requirement).to_a)
  end
end
source_cookbook_added?(name, version) click to toggle source

Determine whether or not the graph has a given cookbook. @param [String] name The name of the cookbook @param [String] version The version of the cookbook @return [Boolean]

# File lib/minimart/mirror/dependency_graph.rb, line 38
def source_cookbook_added?(name, version)
  graph.artifact?(name, version)
end

Private Instance Methods

load_dependencies?() click to toggle source
# File lib/minimart/mirror/dependency_graph.rb, line 66
def load_dependencies?
  Minimart::Configuration.load_deps
end
resolve_requirement(requirement) click to toggle source
# File lib/minimart/mirror/dependency_graph.rb, line 70
def resolve_requirement(requirement)
  Solve.it!(graph, [requirement])

rescue Solve::Errors::NoSolutionError => e
  raise Error::UnresolvedDependency, e.message
end