Class: JavaClass::Dependencies::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/javaclass/dependencies/graph.rb

Overview

A graph contains a list of Node

Author

Peter Kofler

Instance Method Summary collapse

Constructor Details

#initializeGraph

Returns a new instance of Graph.



13
14
15
# File 'lib/javaclass/dependencies/graph.rb', line 13

def initialize
  @nodes = []
end

Instance Method Details

#add(node) ⇒ Object

Add a node to this graph.



18
19
20
# File 'lib/javaclass/dependencies/graph.rb', line 18

def add(node)
  @nodes << node
end

#each_node(&block) ⇒ Object

Iterate all nodes in this Graph and call block for each Node



46
47
48
# File 'lib/javaclass/dependencies/graph.rb', line 46

def each_node(&block)
  @nodes.each { |node| block.call(node) }
end

#nodes_satisfying(dependency) ⇒ Object

Find the nodes that satisfy the given dependency



41
42
43
# File 'lib/javaclass/dependencies/graph.rb', line 41

def nodes_satisfying(dependency)
  @nodes.find_all { |n| n.satisfies?(dependency) }
end

#resolve_dependenciesObject

Iterates all nodes and fills the dependency fields of the Node.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/javaclass/dependencies/graph.rb', line 27

def resolve_dependencies
  @nodes.each do |node|
    puts "processing #{node}"

    node.outgoing_dependencies do |dependency|
      providers = nodes_satisfying(dependency.target)
      node.add_dependency(dependency, providers)
    end
    
    node.dependencies.values.each { |vals| vals.sort! }
  end
end

#to_aObject



22
23
24
# File 'lib/javaclass/dependencies/graph.rb', line 22

def to_a
  @nodes.dup
end