Class: CycleDetector
- Inherits:
-
Object
- Object
- CycleDetector
- Defined in:
- lib/cpp_dependency_graph/cycle_detector.rb
Overview
Detects cycles between components
Instance Method Summary collapse
- #cyclic?(source, target) ⇒ Boolean
-
#initialize(component_links) ⇒ CycleDetector
constructor
A new instance of CycleDetector.
- #to_s ⇒ Object
Constructor Details
#initialize(component_links) ⇒ CycleDetector
7 8 9 10 11 12 13 14 15 |
# File 'lib/cpp_dependency_graph/cycle_detector.rb', line 7 def initialize(component_links) @cyclic_links = {} component_links.each do |source, links| links.each do |target| links_of_target = component_links[target] @cyclic_links[CyclicLink.new(source, target)] = true if links_of_target.include?(source) end end end |
Instance Method Details
#cyclic?(source, target) ⇒ Boolean
17 18 19 20 |
# File 'lib/cpp_dependency_graph/cycle_detector.rb', line 17 def cyclic?(source, target) k = CyclicLink.new(source, target) @cyclic_links.key?(k) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/cpp_dependency_graph/cycle_detector.rb', line 22 def to_s @cyclic_links.each { |k, _| puts k } end |