Class: CovLoupe::Commands::TotalsCommand

Inherits:
BaseCommand show all
Defined in:
lib/cov_loupe/commands/totals_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



9
10
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
44
45
46
47
48
49
50
51
52
53
# File 'lib/cov_loupe/commands/totals_command.rb', line 9

def execute(args)
  reject_extra_args(args, 'totals')

  presenter = Presenters::ProjectTotalsPresenter.new(
    model:          model,
    raise_on_stale: config.raise_on_stale,
    tracked_globs:  config.tracked_globs
  )
  payload = presenter.absolute_payload
  return if maybe_output_structured_format?(payload, model)

  lines = payload['lines']
  files = payload['files']
  tracking = payload['tracking']
  with_coverage = files['with_coverage']
  without_coverage = files['without_coverage']

  if tracking && tracking['enabled']
    puts 'Tracked globs:'
    tracking['globs'].each { |glob| puts "  - #{convert_text(glob)}" }
  else
    puts 'Tracked globs: (tracking disabled)'
  end
  puts

  percent_display = lines['percentage'].nil? ? 'n/a' : format('%.2f%%', lines['percentage'])
  puts "Lines (#{lines['included_files']} ok files): " \
    "#{lines['total']} total, #{lines['covered']} covered, " \
    "#{lines['uncovered']} uncovered (#{percent_display})"
  with_coverage_line = format_with_coverage_line(with_coverage)
  stale_line = format_stale_breakdown(with_coverage['stale']['by_type'])
  without_coverage_line, without_breakdown_line =
    format_without_coverage_lines(without_coverage)

  puts <<~BREAKDOWN

    File breakdown:
    #{with_coverage_line}
    #{stale_line}
    #{without_coverage_line}
    #{without_breakdown_line}
  BREAKDOWN

  warn_missing_timestamps(presenter)
end