Class: CovLoupe::Commands::SummaryCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/cov_loupe/commands/summary_command.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#cli, #config, #source_formatter

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from CovLoupe::Commands::BaseCommand

Instance Method Details

#execute(args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cov_loupe/commands/summary_command.rb', line 11

def execute(args)
  handle_with_path(args, 'summary') do |path|
    presenter = Presenters::CoveragePayloadPresenter.new(model: model, path: path,
      payload_method: :summary_for)
    data = presenter.absolute_payload
    break if emit_structured_format_with_optional_source?(data, model, path)

    relative_path = convert_text(presenter.relative_path)
    summary = data['summary']

    # Table format with box-drawing
    headers = ['File', '%', 'Covered', 'Total', 'Stale']
    stale_marker = StaleStatus.stale?(data['stale']) ? 'Yes' : ''
    percent_display = summary['percentage'] ? format('%.2f%%', summary['percentage']) : 'n/a'.rjust(6)

    rows = [[
      relative_path,
      percent_display,
      summary['covered'].to_s,
      summary['total'].to_s,
      stale_marker,
    ]]

    puts TableFormatter.format(
      headers:      headers,
      rows:         rows,
      alignments:   %i[left right right right center],
      output_chars: config.output_chars
    )
    puts
    print_source_for(model, path) if config.source_mode
  end
end