Class: Reviewer::Session::Formatter

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

Overview

Display logic for lifecycle warnings: unrecognized keywords, no matching tools, etc.

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 session lifecycle warnings

Parameters:

  • output (Output)

    the console output handler



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

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

Instance Method Details

#git_error(message) ⇒ void

This method returns an undefined value.

Displays a git-related error with context-appropriate messaging

Parameters:

  • message (String)

    the error message from the git command



52
53
54
55
56
57
58
59
60
61
# File 'lib/reviewer/session/formatter.rb', line 52

def git_error(message)
  if message.include?('not a git repository')
    printer.puts(:warning, 'Not a git repository')
    printer.puts(:muted, 'Git keywords (staged, modified, etc.) require a git repository')
  else
    printer.puts(:warning, 'Git command failed')
    printer.puts(:muted, message)
    printer.puts(:muted, 'Continuing without file filtering')
  end
end

#invalid_format(value, known) ⇒ void

This method returns an undefined value.

Displays a warning when an unrecognized output format is requested

Parameters:

  • value (String)

    the invalid format name

  • known (Array<Symbol>)

    the valid format options



42
43
44
45
46
# File 'lib/reviewer/session/formatter.rb', line 42

def invalid_format(value, known)
  printer.puts(:warning, "Unknown format '#{value}', using 'streaming'")
  printer.puts(:muted, "Valid formats: #{known.join(', ')}")
  output.newline
end

#no_matching_tools(requested:, available:) ⇒ void

This method returns an undefined value.

Displays a warning when no configured tools match the requested names or tags

Parameters:

  • requested (Array<String>)

    tool names or tags the user asked for

  • available (Array<String>)

    all configured tool keys



78
79
80
81
82
83
84
# File 'lib/reviewer/session/formatter.rb', line 78

def no_matching_tools(requested:, available:)
  output.newline
  printer.puts(:warning, 'No matching tools found')
  printer.puts(:muted, "Requested: #{requested.join(', ')}") if requested.any?
  printer.puts(:muted, "Available: #{available.join(', ')}") if available.any?
  output.newline
end

#no_reviewable_files(keywords:) ⇒ void

This method returns an undefined value.

Displays a message when file-scoping keywords resolved to no files

Parameters:

  • keywords (Array<String>)

    the file keywords that were requested (e.g. [‘staged’])



67
68
69
70
71
# File 'lib/reviewer/session/formatter.rb', line 67

def no_reviewable_files(keywords:)
  output.newline
  printer.puts(:muted, "No reviewable #{keywords.join(', ')} files found")
  output.newline
end

#unrecognized_keywords(unrecognized, suggestions) ⇒ void

This method returns an undefined value.

Displays warnings for keywords that don’t match any tool or git scope

Parameters:

  • unrecognized (Array<String>)

    the unrecognized keyword strings

  • suggestions (Hash{String => String})

    keyword => suggested correction



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

def unrecognized_keywords(unrecognized, suggestions)
  unrecognized.each do |keyword|
    printer.puts(:warning, "Unrecognized: #{keyword}")
    suggestion = suggestions[keyword]
    printer.puts(:muted, "  did you mean '#{suggestion}'?") if suggestion
  end
  output.newline
end