Module: SemanticPuppet::Dependency

Extended by:
Dependency
Included in:
Dependency
Defined in:
lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency.rb,
lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph.rb,
lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/source.rb,
lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb,
lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/module_release.rb,
lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/unsatisfiable_graph.rb

Defined Under Namespace

Modules: GraphNode Classes: Graph, ModuleRelease, Source, UnsatisfiableGraph

Sources collapse

Instance Method Summary collapse

Instance Method Details

#add_source(source) ⇒ void

This method returns an undefined value.

Appends a new Source to the current list.

Parameters:



24
25
26
27
28
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency.rb', line 24

def add_source(source)
  sources
  @sources << source
  nil
end

#clear_sourcesvoid

This method returns an undefined value.

Clears the current list of Sources.



32
33
34
35
36
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency.rb', line 32

def clear_sources
  sources
  @sources.clear
  nil
end

#fetch_releases(name) ⇒ Array<ModuleRelease>

Fetches all available releases for the given module name.

Parameters:

  • name (String)

    the module name to find releases for

Returns:



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/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) ⇒ Graph

TODO:

Return a specialized “Graph” object.

TODO:

Allow for external constraints to be added to the graph.

Fetches a graph of modules and their dependencies from the currently configured list of Sources.

Parameters:

  • modules ({ String => String })

Returns:

  • (Graph)

    the root of a dependency graph

See Also:



51
52
53
54
55
56
57
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/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) ⇒ Array<ModuleRelease>

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.

Parameters:

  • graph (Graph)

    the root of a dependency graph

Returns:

Raises:



66
67
68
69
70
71
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency.rb', line 66

def resolve(graph)
  catch :next do
    return walk(graph, graph.dependencies.dup)
  end
  raise UnsatisfiableGraph.new(graph)
end

#sourcesArray<Source>

Returns a frozen copy of the Source list.

Returns:



17
18
19
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency.rb', line 17

def sources
  (@sources ||= []).dup.freeze
end