Class: JavaClass::Dependencies::Graph
- Defined in:
- lib/javaclass/dependencies/graph.rb
Overview
A graph contains a list of Node
- Author
-
Peter Kofler
Instance Method Summary collapse
-
#add(node) ⇒ Object
Add a node to this graph.
-
#each_node(&block) ⇒ Object
Iterate all nodes in this Graph and call block for each Node.
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
-
#nodes_satisfying(dependency) ⇒ Object
Find the nodes that satisfy the given dependency.
-
#resolve_dependencies ⇒ Object
Iterates all nodes and fills the dependency fields of the Node.
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ Graph
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 (dependency) @nodes.find_all { |n| n.satisfies?(dependency) } end |
#resolve_dependencies ⇒ Object
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 = (dependency.target) node.add_dependency(dependency, providers) end node.dependencies.values.each { |vals| vals.sort! } end end |
#to_a ⇒ Object
22 23 24 |
# File 'lib/javaclass/dependencies/graph.rb', line 22 def to_a @nodes.dup end |