Class: God::DependencyGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/god/dependency_graph.rb,
lib/god/dependency_graph.rb

Defined Under Namespace

Classes: Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDependencyGraph

Returns a new instance of DependencyGraph.



5
6
7
# File 'lib/god/dependency_graph.rb', line 5

def initialize
  self.nodes = {}
end

Instance Attribute Details

#nodesObject

Returns the value of attribute nodes.



3
4
5
# File 'lib/god/dependency_graph.rb', line 3

def nodes
  @nodes
end

Instance Method Details

#add(a, b) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/god/dependency_graph.rb', line 9

def add(a, b)
  node_a = self.nodes[a] || Node.new(a)
  node_b = self.nodes[b] || Node.new(b)
  
  node_a.add(node_b)
  
  self.nodes[a] ||= node_a
  self.nodes[b] ||= node_b
end