class ArchSpec::Rules::ConcernIndependenceRule
Backs ArchSpec::DSL::ComponentProxy#cannot_reference_includers. A concern is a module mixed into other classes; this flags a concern that names the very constant that includes it, which is a circular knowledge dependency.
Constants
- MIXIN_TYPES
Attributes
Public Class Methods
Source
# File lib/archspec/rules/concern_rules.rb, line 13 def initialize(source) @source = source.to_sym end
Public Instance Methods
Source
# File lib/archspec/rules/concern_rules.rb, line 25 def evaluate(graph) component = graph.components[source] return [] unless component includers = includers_by_module(graph) graph.dependency_edges.filter_map do |edge| next unless edge.from_constant && component.constants.include?(edge.from_constant) consumers = includers[edge.from_constant] next if consumers.empty? target = graph.resolve_constant_reference(edge.to, edge.from_constant) includer = consumers.find { |name| target == name || target.start_with?("#{name}::") } next unless includer Diagnostic.new( rule: id, message: "#{edge.from_constant} must not reference its includer #{includer}", location: edge.location, evidence: "#{edge.from_constant} #{edge.type} #{target}" ) end end
Source
# File lib/archspec/rules/concern_rules.rb, line 17 def merge_key [self.class, source] end