module SemanticPuppet::Dependency::GraphNode

Public Instance Methods

<<(nodes) click to toggle source
# File lib/semantic_puppet/dependency/graph_node.rb, line 101
def << (nodes)
  Array(nodes).each do |node|
    next unless dependencies.key?(node.name)
    if satisfies_dependency?(node)
      dependencies[node.name] << node
    end
  end

  return self
end
<=>(other) click to toggle source
# File lib/semantic_puppet/dependency/graph_node.rb, line 112
def <=>(other)
  name <=> other.name
end
add_constraint(source, mod, desc, &block) click to toggle source

Constrains the named module to suitable releases, as determined by the given block.

@example Version-locking currently installed modules

installed_modules.each do |m|
  @graph.add_constraint('installed', m.name, m.version) do |node|
    m.version == node.version
  end
end

@param source [String, Symbol] a name describing the source of the

constraint

@param mod [String] the name of the module @param desc [String] a description of the enforced constraint @yieldparam node [GraphNode] the node to test the constraint against @yieldreturn [Boolean] whether the node passed the constraint @return [void]

# File lib/semantic_puppet/dependency/graph_node.rb, line 88
def add_constraint(source, mod, desc, &block)
  constraints["#{mod}"] << [ source, desc, block ]
end
add_dependency(name) click to toggle source

Adds the given dependency name to the list of dependencies.

@param name [String] the dependency name @return [void]

# File lib/semantic_puppet/dependency/graph_node.rb, line 46
def add_dependency(name)
  dependencies[name]
end
children() click to toggle source
# File lib/semantic_puppet/dependency/graph_node.rb, line 20
def children
  @_children ||= {}
end
constraints() click to toggle source
# File lib/semantic_puppet/dependency/graph_node.rb, line 55
def constraints
  @_constraints ||= Hash.new { |h, k| h[k] = [] }
end
constraints_for(name) click to toggle source
# File lib/semantic_puppet/dependency/graph_node.rb, line 59
def constraints_for(name)
  return [] unless constraints.has_key?(name)

  constraints[name].map do |constraint|
    {
      :source      => constraint[0],
      :description => constraint[1],
      :test        => constraint[2],
    }
  end
end
dependencies() click to toggle source

@api internal @return [{ String => SortedSet<GraphNode> }] the satisfactory

dependency nodes
# File lib/semantic_puppet/dependency/graph_node.rb, line 38
def dependencies
  @_dependencies ||= Hash.new { |h, k| h[k] = SortedSet.new }
end
dependency_names() click to toggle source

@return [Array<String>] the list of dependency names

# File lib/semantic_puppet/dependency/graph_node.rb, line 51
def dependency_names
  dependencies.keys
end
name() click to toggle source
# File lib/semantic_puppet/dependency/graph_node.rb, line 9
def name
end
populate_children(nodes) click to toggle source
# File lib/semantic_puppet/dependency/graph_node.rb, line 24
def populate_children(nodes)
  if children.empty?
    nodes = nodes.select { |node| satisfies_dependency?(node) }
    nodes.each do |node|
      children[node.name] = node
      node.populate_children(nodes)
    end
    self.freeze
  end
end
satisfied?() click to toggle source

Determines whether the modules dependencies are satisfied by the known releases.

@return [Boolean] true if all dependencies are satisfied

# File lib/semantic_puppet/dependency/graph_node.rb, line 16
def satisfied?
  dependencies.none? { |_, v| v.empty? }
end
satisfies_constraints?(release) click to toggle source

@param release [ModuleRelease] the release to test

# File lib/semantic_puppet/dependency/graph_node.rb, line 97
def satisfies_constraints?(release)
  constraints_for(release.name).all? { |x| x[:test].call(release) }
end
satisfies_dependency?(node) click to toggle source
# File lib/semantic_puppet/dependency/graph_node.rb, line 92
def satisfies_dependency?(node)
  dependencies.key?(node.name) && satisfies_constraints?(node)
end