Class: Reviewer::Session::Formatter
- Inherits:
-
Object
- Object
- Reviewer::Session::Formatter
- Includes:
- Output::Formatting
- Defined in:
- lib/reviewer/session/formatter.rb
Overview
Display logic for lifecycle warnings: unrecognized keywords, no matching tools, etc.
Constant Summary collapse
- MISSING_FILES_MESSAGE =
'The --files option requires at least one file or path.'
Constants included from Output::Formatting
Output::Formatting::CHECKMARK, Output::Formatting::XMARK
Instance Method Summary collapse
-
#git_error(message) ⇒ void
Displays a git-related error with context-appropriate messaging.
-
#initialize(output) ⇒ Formatter
constructor
Creates a formatter for session lifecycle warnings.
-
#invalid_format(value, known) ⇒ void
Displays a warning when an unrecognized output format is requested.
-
#missing_files_option ⇒ void
Displays a usage error when -f/--files has no value.
-
#missing_files_option_json ⇒ void
Renders the machine-readable form of the missing files usage error.
-
#no_matching_tools(requested:, available:) ⇒ void
Displays a warning when no configured tools match the requested names or tags.
-
#no_reviewable_files(keywords:) ⇒ void
Displays a message when file-scoping keywords resolved to no files.
-
#unrecognized_keywords(unrecognized, suggestions) ⇒ void
Displays warnings for keywords that don't match any tool or git scope.
-
#unrecognized_keywords_json(unrecognized, suggestions) ⇒ void
Renders a machine-readable envelope for a name Reviewer cannot honour.
Constructor Details
#initialize(output) ⇒ Formatter
Creates a formatter for session lifecycle warnings
20 21 22 23 |
# File 'lib/reviewer/session/formatter.rb', line 20 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
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/reviewer/session/formatter.rb', line 98 def git_error() if .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, ) 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
88 89 90 91 92 |
# File 'lib/reviewer/session/formatter.rb', line 88 def invalid_format(value, known) printer.puts(:warning, "Unknown format '#{value}', using 'streaming'") printer.puts(:muted, "Valid formats: #{known.join(', ')}") output.newline end |
#missing_files_option ⇒ void
This method returns an undefined value.
Displays a usage error when -f/--files has no value
63 64 65 66 |
# File 'lib/reviewer/session/formatter.rb', line 63 def missing_files_option printer.puts(:warning, MISSING_FILES_MESSAGE) output.newline end |
#missing_files_option_json ⇒ void
This method returns an undefined value.
Renders the machine-readable form of the missing files usage error
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/reviewer/session/formatter.rb', line 71 def missing_files_option_json payload = { schema_version: Report::SCHEMA_VERSION, state: 'error', error: { code: 'missing_files', message: MISSING_FILES_MESSAGE }, summary: Report.empty_summary, tools: [] } printer.write_raw("#{JSON.pretty_generate(payload)}\n") 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
124 125 126 127 128 129 130 |
# File 'lib/reviewer/session/formatter.rb', line 124 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
113 114 115 116 117 |
# File 'lib/reviewer/session/formatter.rb', line 113 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
30 31 32 33 34 35 36 37 |
# File 'lib/reviewer/session/formatter.rb', line 30 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 |
#unrecognized_keywords_json(unrecognized, suggestions) ⇒ void
This method returns an undefined value.
Renders a machine-readable envelope for a name Reviewer cannot honour
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/reviewer/session/formatter.rb', line 44 def unrecognized_keywords_json(unrecognized, suggestions) payload = { schema_version: Report::SCHEMA_VERSION, state: 'error', error: { code: 'unrecognized_selector', message: "Unrecognized: #{unrecognized.join(', ')}", suggestions: suggestions }, summary: Report.empty_summary, tools: [] } printer.write_raw("#{JSON.pretty_generate(payload)}\n") end |