Class: CovLoupe::StalenessMessageFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/cov_loupe/staleness/staleness_message_formatter.rb

Overview

Formats staleness error messages with human-readable timestamps and file lists.

Used by CoverageDataStaleError and CoverageDataProjectStaleError to produce consistent, detailed diagnostics. Includes UTC and local times for both coverage generation and source file modification, plus the delta in seconds.

File lists are capped at 10 entries to keep error messages readable.

Instance Method Summary collapse

Constructor Details

#initialize(cov_timestamp:, resultset_path: nil, output_chars: :default) ⇒ StalenessMessageFormatter

Returns a new instance of StalenessMessageFormatter.



14
15
16
17
18
# File 'lib/cov_loupe/staleness/staleness_message_formatter.rb', line 14

def initialize(cov_timestamp:, resultset_path: nil, output_chars: :default)
  @cov_timestamp = cov_timestamp
  @resultset_path = resultset_path
  @output_chars = output_chars
end

Instance Method Details

#format_project_details(newer_files:, missing_files:, deleted_files:, length_mismatch_files:, unreadable_files: []) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cov_loupe/staleness/staleness_message_formatter.rb', line 20

def format_project_details(newer_files:, missing_files:, deleted_files:,
  length_mismatch_files:, unreadable_files: [])
  [
    format_coverage_time,
    *format_file_list(newer_files, 'Newer files'),
    *format_file_list(missing_files, 'Missing files', 'new in project, not in coverage'),
    *format_file_list(deleted_files, 'Coverage-only files', 'deleted or moved in project'),
    *format_file_list(length_mismatch_files, 'Line count mismatches'),
    *format_file_list(unreadable_files, 'Unreadable files', 'permission denied or read errors'),
    (@resultset_path ? "\nResultset - #{convert_path(@resultset_path)}" : nil),
  ].compact.join
end

#format_single_file_details(file_path:, file_mtime:, src_len:, cov_len:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cov_loupe/staleness/staleness_message_formatter.rb', line 33

def format_single_file_details(file_path:, file_mtime:, src_len:, cov_len:)
  file_utc, file_local = format_time_both(file_mtime)
  cov_utc, cov_local = format_epoch_both(@cov_timestamp)
  delta_str = format_delta_seconds(file_mtime, @cov_timestamp)

  details = <<~DETAILS

    File     - time: #{file_utc || 'not found'} (local #{file_local || 'n/a'}), lines: #{src_len}
    Coverage - time: #{cov_utc  || 'not found'} (local #{cov_local  || 'n/a'}), lines: #{cov_len}
    DETAILS

  details += "\nDelta    - file is #{delta_str} newer than coverage" if delta_str
  details += "\nResultset - #{convert_path(@resultset_path)}" if @resultset_path
  details.chomp
end