Class: SimpleCov::Formatter::AIFormatter::MarkdownBuilder::SectionWriter

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/simplecov-ai/markdown_builder/section_writer.rb

Overview

Writes one report section (## Coverage Deficits, ## Ignored Coverage Bypasses) through the ReportBudget at semantic-node granularity. The section heading travels with the first file block so a heading never stands without content; each file block is its heading plus one fragment per node, admitted one at a time, so truncation loses at most the tail of a single file. Once a fragment is rejected the section closes and later files are counted as omitted, which keeps the "lowest-coverage files first" ordering promise intact.

Constant Summary collapse

FILE_HEADING_TEMPLATE =

Template for file-level headings in both sections

T.let('### %s', String)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(budget, heading) ⇒ SectionWriter

Returns a new instance of SectionWriter.



28
29
30
31
32
33
34
# File 'lib/simplecov-ai/markdown_builder/section_writer.rb', line 28

def initialize(budget, heading)
  @budget = budget
  @heading = heading
  @heading_pending = T.let(true, T::Boolean)
  @closed = T.let(false, T::Boolean)
  @written_blocks = T.let(0, Integer)
end

Instance Attribute Details

#written_blocksObject (readonly)

Returns the value of attribute written_blocks.



23
24
25
# File 'lib/simplecov-ai/markdown_builder/section_writer.rb', line 23

def written_blocks
  @written_blocks
end

Class Method Details

.file_heading(file) ⇒ Object



41
42
43
# File 'lib/simplecov-ai/markdown_builder/section_writer.rb', line 41

def self.file_heading(file)
  format(FILE_HEADING_TEMPLATE, InlineCode.span(file.project_filename.delete_prefix('/')))
end

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/simplecov-ai/markdown_builder/section_writer.rb', line 47

def closed?
  @closed
end

#write_file_block(file_heading, node_fragments) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/simplecov-ai/markdown_builder/section_writer.rb', line 59

def write_file_block(file_heading, node_fragments)
  return if @closed

  first_fragment, *further_fragments = node_fragments
  opening = "#{@heading if @heading_pending}#{file_heading}\n#{first_fragment}"
  return close!(block_started: false) unless @budget.admit(opening)

  @heading_pending = false
  return close!(block_started: true) unless further_fragments.all? { |fragment| @budget.admit(fragment) }

  @budget.write("\n")
  @written_blocks += 1
end