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 96 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 114 def evaluate(graph) graph.dependency_edges.flat_map do |edge| next [] unless graph.target_components_for(edge).include?(source) offenders = graph.component_names_for_path(edge.from_path).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: "#{edge.from_constant || edge.from_path} #{edge.type} #{edge.to}" ) end end end
Source
# File lib/archspec/rules/dependency_rules.rb, line 110 def id 'dependencies.consumers' end
Source
# File lib/archspec/rules/dependency_rules.rb, line 105 def merge!(other) consumers.merge(other.consumers) self end
Source
# File lib/archspec/rules/dependency_rules.rb, line 101 def merge_key [self.class, source] end