Class: Depdump::DependencyGraph
- Inherits:
-
Object
- Object
- Depdump::DependencyGraph
- Defined in:
- lib/depdump/dependency_graph.rb
Defined Under Namespace
Modules: Formatter
Instance Attribute Summary collapse
-
#edges ⇒ Object
readonly
Returns the value of attribute edges.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #build(tree) ⇒ Object
- #format ⇒ Object
-
#initialize(tree) ⇒ DependencyGraph
constructor
A new instance of DependencyGraph.
Constructor Details
#initialize(tree) ⇒ DependencyGraph
Returns a new instance of DependencyGraph.
7 8 9 10 11 |
# File 'lib/depdump/dependency_graph.rb', line 7 def initialize(tree) @nodes = Set.new @edges = Set.new build(tree) end |
Instance Attribute Details
#edges ⇒ Object (readonly)
Returns the value of attribute edges.
5 6 7 |
# File 'lib/depdump/dependency_graph.rb', line 5 def edges @edges end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
5 6 7 |
# File 'lib/depdump/dependency_graph.rb', line 5 def nodes @nodes end |
Instance Method Details
#build(tree) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/depdump/dependency_graph.rb', line 13 def build(tree) tree.each_node do |node| next if node == tree.root @nodes << node node.relations.each do |r| referenced_namespaces = r.resolve(tree) if referenced_namespaces @edges << { from: node.namespaces, to: referenced_namespaces } else # TODO: Show file path and line no. warn "[skip] cannot resolve: #{node.namespaces} => #{r.reference}" end end end end |