Class: SemanticPuppet::Dependency::Graph

Inherits:
Object
  • Object
show all
Includes:
GraphNode
Defined in:
lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GraphNode

#<<, #<=>, #add_constraint, #add_dependency, #children, #constraints, #constraints_for, #dependencies, #dependency_names, #name, #populate_children, #satisfied?, #satisfies_constraints?, #satisfies_dependency?

Constructor Details

#initialize(modules = {}) ⇒ Graph

Create a new instance of a dependency graph.

Parameters:

  • modules ({String => VersionRange}) (defaults to: {})

    the required module set and their version constraints



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph.rb', line 14

def initialize(modules = {})
  @modules = modules.keys

  modules.each do |name, range|
    add_constraint('initialize', name, range.to_s) do |node|
      range === node.version
    end

    add_dependency(name)
  end
end

Instance Attribute Details

#modulesObject (readonly)

Returns the value of attribute modules.



8
9
10
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph.rb', line 8

def modules
  @modules
end

Instance Method Details

#add_graph_constraint(source) {|nodes| ... } ⇒ void

This method returns an undefined value.

Constrains graph solutions based on the given block. Graph constraints are used to describe fundamental truths about the tooling or module system (e.g.: module names contain a namespace component which is dropped during install, so module names must be unique excluding the namespace).

Examples:

Ensuring a single source for all modules

@graph.add_constraint('installed', mod.name) do |nodes|
  nodes.count { |node| node.source } == 1
end

Parameters:

  • source (String, Symbol)

    a name describing the source of the constraint

Yield Parameters:

  • nodes (Array<GraphNode>)

    the nodes to test the constraint against

Yield Returns:

  • (Boolean)

    whether the node passed the constraint

See Also:

  • #considering_solution?


45
46
47
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph.rb', line 45

def add_graph_constraint(source, &block)
  constraints[:graph] << [ source, block ]
end

#satisfies_graph?(solution) ⇒ Boolean

Checks the proposed solution (or partial solution) against the graph’s constraints.

Returns:

  • (Boolean)

    true if none of the graph constraints are violated

See Also:



55
56
57
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph.rb', line 55

def satisfies_graph?(solution)
  constraints[:graph].all? { |_, check| check[solution] }
end