Class: ArchUnit::Testing::ViolationFactory

Inherits:
Object
  • Object
show all
Extended by:
LayerViolationFormatter, MetricViolationFormatter, SliceViolationFormatter
Defined in:
lib/archunit/testing/violation_factory.rb

Overview

The sole mapping from structured violation data to human-readable prose.

Constant Summary collapse

FORMATTERS =
{
  Common::Assertion::EmptyTestViolation => :empty_test,
  Files::Assertion::FilePatternViolation => :file_pattern,
  Files::Assertion::FileDependencyViolation => :file_dependency,
  Files::Assertion::ExternalModuleDependencyViolation => :external_module_dependency,
  Files::Assertion::CycleViolation => :cycle,
  Files::Assertion::CustomFileViolation => :custom_file,
  Layers::Assertion::LayerDependencyViolation => :layer_dependency,
  Slices::Assertion::SliceDependencyViolation => :slice_dependency
}.merge(MetricViolationFormatter::FORMATTERS).freeze

Class Method Summary collapse

Class Method Details

.from_violation(violation) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/archunit/testing/violation_factory.rb', line 42

def from_violation(violation)
  unless violation.is_a?(Common::Assertion::Violation)
    raise ArgumentError, 'violation must be a Violation'
  end

  formatter = FORMATTERS.find { |type, _method| violation.is_a?(type) }&.last
  formatter ? send(formatter, violation) : generic(violation)
end