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_edge_constant(edge) owner = [edge.from_constant, *consumers] .select { |namespace| within_namespace?(target, namespace) } .max_by(&:length) next unless consumers.include?(owner) Diagnostic.new( rule: id, message: "#{edge.from_constant} must not reference its includer #{owner}", location: edge.location, evidence: "#{edge.from_constant} #{edge.verb} #{target}" ) end end
Source
# File lib/archspec/rules/concern_rules.rb, line 17 def merge_key [self.class, source] end