Class: CovLoupe::Commands::DetailedCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/cov_loupe/commands/detailed_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
# File 'lib/cov_loupe/commands/detailed_command.rb', line 11

def execute(args)
  handle_with_path(args, 'detailed') do |path|
    presenter = Presenters::CoveragePayloadPresenter.new(model: model, path: path,
      payload_method: :detailed_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']
    puts "File: #{relative_path}"
    puts "Coverage: #{summary['covered']}/#{summary['total']} lines (#{format('%.2f%%',
      summary['percentage'])})"
    puts "Stale: #{data['stale']}" if StaleStatus.stale?(data['stale'])
    puts

    # Table format with box-drawing
    headers = %w[Line Hits Covered]
    rows = data['lines'].map do |r|
      [r['line'].to_s, r['hits'].to_s, r['covered'] ? 'yes' : 'no']
    end

    puts TableFormatter.format(
      headers:      headers,
      rows:         rows,
      alignments:   %i[right right center],
      output_chars: config.output_chars
    )

    print_source_for(model, path) if config.source_mode
  end
end