class ArchSpec::Rules::CannotReferenceConstantsRule
Backs ArchSpec::DSL::ComponentProxy#cannot_reference_constants. Flags references to the named constants or anything nested under them.
Attributes
Public Class Methods
Source
# File lib/archspec/rules/dependency_rules.rb, line 139 def initialize(source, constants) @source = source.to_sym @constants = Array(constants).flatten.map { |constant| constant.to_s.sub(/\A::/, '') } end
Public Instance Methods
Source
# File lib/archspec/rules/dependency_rules.rb, line 157 def evaluate(graph) graph.dependency_edges.filter_map do |edge| next unless graph.source_components_for(edge).include?(source) referenced = graph.resolve_edge_constant(edge) next unless constants.any? { |constant| referenced == constant || referenced.start_with?("#{constant}::") } Diagnostic.new( rule: id, message: "#{source} must not reference #{referenced}", location: edge.location, evidence: "#{graph.edge_source_name(edge)} #{edge.verb} #{edge.to}" ) end end
Source
# File lib/archspec/rules/dependency_rules.rb, line 148 def merge!(other) @constants |= other.constants self end
Source
# File lib/archspec/rules/dependency_rules.rb, line 144 def merge_key [self.class, source] end