Class: ArchSpec::Rules::ConcernIndependenceRule
- Inherits:
-
Object
- Object
- ArchSpec::Rules::ConcernIndependenceRule
- Defined in:
- lib/archspec/rules/concern_rules.rb
Overview
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.
Constant Summary collapse
- MIXIN_TYPES =
%i[includes prepends extends].freeze
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #evaluate(graph) ⇒ Object
- #id ⇒ Object
-
#initialize(source) ⇒ ConcernIndependenceRule
constructor
A new instance of ConcernIndependenceRule.
- #merge_key ⇒ Object
Constructor Details
#initialize(source) ⇒ ConcernIndependenceRule
Returns a new instance of ConcernIndependenceRule.
13 14 15 |
# File 'lib/archspec/rules/concern_rules.rb', line 13 def initialize(source) @source = source.to_sym end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
11 12 13 |
# File 'lib/archspec/rules/concern_rules.rb', line 11 def source @source end |
Instance Method Details
#evaluate(graph) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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 |
#id ⇒ Object
21 22 23 |
# File 'lib/archspec/rules/concern_rules.rb', line 21 def id 'concerns.independence' end |
#merge_key ⇒ Object
17 18 19 |
# File 'lib/archspec/rules/concern_rules.rb', line 17 def merge_key [self.class, source] end |