class ArchSpec::Rules::NoCyclesRule
Backs ArchSpec::DSL::Context#no_cycles. Flags each group of components that depend on each other, reporting the group once with an example cycle.
Attributes
Public Class Methods
Source
# File lib/archspec/rules/cycle_rule.rb, line 10 def initialize(among: nil) @components = Array(among).compact.map(&:to_sym) end
Public Instance Methods
Source
# File lib/archspec/rules/cycle_rule.rb, line 22 def evaluate(graph) locations = dependency_locations(graph) adjacency = adjacency_for(locations) StronglyConnectedComponents.of(adjacency).filter_map do |group| next if group.size < 2 cycle = shortest_cycle(adjacency, group) next unless cycle Diagnostic.new( rule: id, message: message_for(group, cycle), location: locations[[cycle[0], cycle[1]]] || SourceLocation.point(graph.root, 1, 1), evidence: cycle.join(' -> ') ) end end
One diagnostic per strongly connected component. Every component in an SCC reaches every other one, so the group is the thing to break up; enumerating its elementary cycles instead reports the same tangle exponentially many times.