Module: ArchUnit::Common::Logging::Inspection

Defined in:
lib/archunit/common/logging/inspection.rb

Overview

Internal inspection context, scoped to one check and isolated by Ruby fiber.

Class Method Summary collapse

Class Method Details

.debug ⇒ Object



22
23
24
# File 'lib/archunit/common/logging/inspection.rb', line 22

def debug(&)
  logger&.debug(&)
end

.graph(graph, root:) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/archunit/common/logging/inspection.rb', line 26

def graph(graph, root:)
  debug do
    logger.debug { "project root: #{root.to_s.inspect}" }
    graph.each { |edge| logger.debug { describe_edge(edge) } }
    "graph edges: #{graph.size}"
  end
  graph
end

.logger ⇒ Object



18
19
20
# File 'lib/archunit/common/logging/inspection.rb', line 18

def logger
  Thread.current[:archunit_inspection_logger]
end

.projection(edges) ⇒ Object



43
44
45
46
47
# File 'lib/archunit/common/logging/inspection.rb', line 43

def projection(edges)
  selection('projected dependency', edges) do |edge|
    "#{edge.source_label} -> #{edge.target_label} (#{edge.cumulated_edges.length} edges)"
  end
end

.selection(label, items) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/archunit/common/logging/inspection.rb', line 35

def selection(label, items)
  debug do
    items.each { |item| logger.debug { "#{label}: #{yield(item).inspect}" } }
    "#{label} count: #{items.length}"
  end
  items
end

.with(logger) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/archunit/common/logging/inspection.rb', line 10

def with(logger)
  previous = Thread.current[:archunit_inspection_logger]
  Thread.current[:archunit_inspection_logger] = logger
  yield
ensure
  Thread.current[:archunit_inspection_logger] = previous
end