Class: Reviewer::Batch::Formatter

Inherits:
Object
  • Object
show all
Includes:
Output::Formatting
Defined in:
lib/reviewer/batch/formatter.rb

Overview

Display logic for batch execution: summary, run preview, missing tools

Constant Summary

Constants included from Output::Formatting

Output::Formatting::CHECKMARK, Output::Formatting::XMARK

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Formatter

Creates a formatter for batch execution display

Parameters:

  • output (Output)

    the console output handler



18
19
20
21
# File 'lib/reviewer/batch/formatter.rb', line 18

def initialize(output)
  @output = output
  @printer = output.printer
end

Instance Method Details

#missing_tools(missing, tools:) ⇒ void

This method returns an undefined value.

Displays a list of tools whose executables were not found, with install hints

Parameters:

  • missing (Array<Runner::Result>)

    the results for missing tools

  • tools (Array<Tool>)

    the tools that were in the batch



52
53
54
55
56
57
58
# File 'lib/reviewer/batch/formatter.rb', line 52

def missing_tools(missing, tools:)
  output.newline
  printer.puts(:warning, "#{missing.size} not installed:")
  tool_lookup = tools.to_h { |tool| [tool.key, tool] }
  missing.each { |result| print_missing_hint(result.tool_name, tool_lookup[result.tool_key]) }
  output.newline
end

#no_failures_to_retryvoid

This method returns an undefined value.

Displays a message when ‘rvw failed` is used but no tools failed in the last run



63
64
65
# File 'lib/reviewer/batch/formatter.rb', line 63

def no_failures_to_retry
  printer.puts(:muted, 'No failures to retry')
end

#no_previous_runvoid

This method returns an undefined value.

Displays a message when ‘rvw failed` is used but no previous run exists in history



70
71
72
# File 'lib/reviewer/batch/formatter.rb', line 70

def no_previous_run
  printer.puts(:muted, 'No previous run found')
end

#run_summary(entries) ⇒ void

This method returns an undefined value.

Displays a preview of which tools will run and their target files

Parameters:

  • entries (Array<Hash>)

    each with :name and :files keys



40
41
42
43
44
45
# File 'lib/reviewer/batch/formatter.rb', line 40

def run_summary(entries)
  return if entries.empty?

  entries.each { |entry| print_run_entry(entry) }
  output.newline
end

#summary(tool_count, seconds) ⇒ void

This method returns an undefined value.

Displays a one-line success summary with timing and tool count

Parameters:

  • tool_count (Integer)

    the number of tools that ran

  • seconds (Float)

    total elapsed time in seconds



28
29
30
31
32
33
34
# File 'lib/reviewer/batch/formatter.rb', line 28

def summary(tool_count, seconds)
  output.newline
  printer.print(:success, CHECKMARK)
  printer.print(:muted, " ~#{seconds.round(1)} seconds")
  printer.print(:muted, " for #{tool_count} tools") if tool_count > 1
  output.newline
end