Module: Moult::Formatters::CyclesTable

Defined in:
lib/moult/formatters/cycles_table.rb

Overview

Human-readable table of circular file dependencies. Renders from the same CyclesReport as the JSON formatter so the two cannot disagree. Sorting already happened in Cycles; this layer owns column formatting only.

Constant Summary collapse

MAX_FILES =
3
RIGHT_ALIGNED =

CONF, SIZE

[0, 1].freeze

Class Method Summary collapse

Class Method Details

.chain(files) ⇒ Object

"a.rb -> b.rb -> a.rb" for small cycles; "a.rb -> b.rb -> c.rb (+2 more)" once the membership no longer fits.



40
41
42
43
44
45
# File 'lib/moult/formatters/cycles_table.rb', line 40

def chain(files)
  shown = files.first(MAX_FILES)
  extra = files.size - shown.size
  return "#{shown.join(" -> ")} (+#{extra} more)" if extra.positive?
  "#{shown.join(" -> ")} -> #{files.first}"
end

.heading(count) ⇒ Object



25
26
27
# File 'lib/moult/formatters/cycles_table.rb', line 25

def heading(count)
  "Circular file dependencies (constant-resolved): #{count} cycles"
end

.render(report) ⇒ String

Parameters:

Returns:

  • (String)


16
17
18
19
20
21
22
23
# File 'lib/moult/formatters/cycles_table.rb', line 16

def render(report)
  findings = report.findings
  return "No cycles found." if findings.empty?

  headers = %w[CONF SIZE CYCLE FILES]
  rows = findings.map { |f| row(f) }
  [heading(findings.size), "", TextTable.render(headers, rows, right_aligned: RIGHT_ALIGNED)].join("\n")
end

.row(finding) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/moult/formatters/cycles_table.rb', line 29

def row(finding)
  [
    format("%.2f", finding.confidence),
    finding.size.to_s,
    finding.cycle_group,
    chain(finding.files)
  ]
end