class ArchSpec::Rules::AllowedConsumersRule
Backs ArchSpec::DSL::ComponentProxy#can_only_be_used_by. The inverse of an allowlist: flags references to the component from any component that is not an approved consumer. Use it to protect a shared kernel.
Attributes
Public Class Methods
Source
# File lib/archspec/rules/dependency_rules.rb, line 88 def initialize(source, consumers) @source = source.to_sym @consumers = Array(consumers).flatten.map(&:to_sym).to_set end
Public Instance Methods
Source
# File lib/archspec/rules/dependency_rules.rb, line 106 def evaluate(graph) graph.dependency_edges.flat_map do |edge| next [] unless graph.target_components_for(edge).include?(source) offenders = graph.source_components_for(edge).reject do |component| component == source || consumers.include?(component) end offenders.map do |offender| Diagnostic.new( rule: id, message: message_for(offender), location: edge.location, evidence: "#{graph.edge_source_name(edge)} #{edge.verb} #{edge.to}" ) end end end
Source
# File lib/archspec/rules/dependency_rules.rb, line 102 def id 'dependencies.consumers' end
Source
# File lib/archspec/rules/dependency_rules.rb, line 97 def merge!(other) consumers.merge(other.consumers) self end
Source
# File lib/archspec/rules/dependency_rules.rb, line 93 def merge_key [self.class, source] end