module Semantic::Dependency

Public Instance Methods

add_source(source) click to toggle source

Appends a new {Source} to the current list. @param source [Source] the {Source} to add @return [void]

# File lib/puppet/vendor/semantic/lib/semantic/dependency.rb, line 24
def add_source(source)
  sources
  @sources << source
  nil
end
clear_sources() click to toggle source

Clears the current list of {Source}s. @return [void]

# File lib/puppet/vendor/semantic/lib/semantic/dependency.rb, line 32
def clear_sources
  sources
  @sources.clear
  nil
end
fetch_releases(name) click to toggle source

Fetches all available releases for the given module name.

@param name [String] the module name to find releases for @return [Array<ModuleRelease>] the available releases

# File lib/puppet/vendor/semantic/lib/semantic/dependency.rb, line 77
def fetch_releases(name)
  releases = {}

  sources.each do |source|
    source.fetch(name).each do |dependency|
      releases[dependency.version] ||= dependency
    end
  end

  return releases.values
end
query(modules) click to toggle source

Fetches a graph of modules and their dependencies from the currently configured list of {Source}s.

@todo Return a specialized “Graph” object. @todo Allow for external constraints to be added to the graph. @see sources @see add_source @see clear_sources

@param modules [{ String => String }] @return [Graph] the root of a dependency graph

# File lib/puppet/vendor/semantic/lib/semantic/dependency.rb, line 51
def query(modules)
  constraints = Hash[modules.map { |k, v| [ k, VersionRange.parse(v) ] }]

  graph = Graph.new(constraints)
  fetch_dependencies(graph)
  return graph
end
resolve(graph) click to toggle source

Given a graph result from {query}, this method will resolve the graph of dependencies, if possible, into a flat list of the best suited modules. If the dependency graph does not have a suitable resolution, this method will raise an exception to that effect.

@param graph [Graph] the root of a dependency graph @return [Array<ModuleRelease>] the list of releases to act on

# File lib/puppet/vendor/semantic/lib/semantic/dependency.rb, line 66
def resolve(graph)
  catch :next do
    return walk(graph, graph.dependencies.dup)
  end
  raise UnsatisfiableGraph.new(graph)
end
sources() click to toggle source

@return [Array<Source>] a frozen copy of the {Source} list

# File lib/puppet/vendor/semantic/lib/semantic/dependency.rb, line 17
def sources
  (@sources ||= []).dup.freeze
end