Class: ArchSpec::Rules::ForbidDependenciesRule

Inherits:
DependencyRule show all
Defined in:
lib/archspec/rules/dependency_rules.rb

Overview

Backs ArchSpec::DSL::ComponentProxy#cannot_use. Flags references from the source to any of the named components.

Instance Attribute Summary

Attributes inherited from DependencyRule

#source, #targets

Instance Method Summary collapse

Methods inherited from DependencyRule

#initialize, #merge!, #merge_key

Constructor Details

This class inherits a constructor from ArchSpec::Rules::DependencyRule

Instance Method Details

#evaluate(graph) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/archspec/rules/dependency_rules.rb', line 74

def evaluate(graph)
  relevant_edges(graph).flat_map do |edge|
    forbidden = target_components(graph, edge) & targets

    forbidden.map do |target|
      Diagnostic.new(
        rule: id,
        message: "#{source} must not depend on #{target}",
        location: edge.location,
        evidence: "#{edge.from_constant || edge.from_path} #{edge.type} #{edge_target(edge)}"
      )
    end
  end
end

#idObject



70
71
72
# File 'lib/archspec/rules/dependency_rules.rb', line 70

def id
  'dependencies.forbid'
end