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 147 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 165 def evaluate(graph) graph.dependency_edges.filter_map do |edge| next unless graph.component_names_for_path(edge.from_path).include?(source) referenced = graph.resolve_constant_reference(edge.to, edge.from_constant) 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: "#{edge.from_constant || edge.from_path} #{edge.type} #{edge.to}" ) end end
Source
# File lib/archspec/rules/dependency_rules.rb, line 156 def merge!(other) @constants |= other.constants self end
Source
# File lib/archspec/rules/dependency_rules.rb, line 152 def merge_key [self.class, source] end