Class: Gem::Guardian::ResultPrinter
- Inherits:
-
Object
- Object
- Gem::Guardian::ResultPrinter
- Defined in:
- lib/gem/guardian/result_printer.rb
Overview
Formats verification results for human-readable CLI output.
Constant Summary collapse
- USAGE =
CLI usage text.
<<~USAGE.freeze gem-guardian #{VERSION} Usage: gem-guardian verify [--lockfile Gemfile.lock] gem-guardian verify GEM:VERSION[:PLATFORM] [GEM:VERSION[:PLATFORM] ...] gem-guardian version Examples: gem-guardian verify gem-guardian verify sidekiq:8.0.8 gem-guardian verify nokogiri:1.18.9:x86_64-linux USAGE
Instance Method Summary collapse
-
#initialize(stdout:) ⇒ ResultPrinter
constructor
A new instance of ResultPrinter.
-
#print_error_result(result, label) ⇒ Object
Prints an unexpected verifier error.
-
#print_lockfile_coverage(lockfile_data) ⇒ Object
Prints lockfile checksum coverage.
-
#print_mismatch_result(result, label) ⇒ Object
Prints a checksum mismatch.
-
#print_ok_result(result, label, lockfile_mode) ⇒ Object
Prints a successful verification result.
-
#print_result(result, lockfile_mode:) ⇒ Object
Prints one verification result.
-
#print_results(results, lockfile_mode:) ⇒ Object
Prints a collection of verification results.
-
#usage ⇒ Object
Prints the CLI usage text.
Constructor Details
#initialize(stdout:) ⇒ ResultPrinter
Returns a new instance of ResultPrinter.
8 9 10 |
# File 'lib/gem/guardian/result_printer.rb', line 8 def initialize(stdout:) @stdout = stdout end |
Instance Method Details
#print_error_result(result, label) ⇒ Object
Prints an unexpected verifier error.
45 46 47 48 |
# File 'lib/gem/guardian/result_printer.rb', line 45 def print_error_result(result, label) @stdout.puts "ERROR #{label}" @stdout.puts " #{result.error.class}: #{result.error.}" end |
#print_lockfile_coverage(lockfile_data) ⇒ Object
Prints lockfile checksum coverage.
51 52 53 54 55 56 57 58 59 |
# File 'lib/gem/guardian/result_printer.rb', line 51 def print_lockfile_coverage(lockfile_data) covered = lockfile_data.dependencies.size - lockfile_data.missing_checksum_dependencies.size total = lockfile_data.dependencies.size @stdout.puts "CHECKSUMS coverage: #{covered}/#{total}" lockfile_data.missing_checksum_dependencies.each do |dependency| @stdout.puts "MISSING #{dependency.name} #{dependency.version} #{dependency.platform}" end end |
#print_mismatch_result(result, label) ⇒ Object
Prints a checksum mismatch.
38 39 40 41 42 |
# File 'lib/gem/guardian/result_printer.rb', line 38 def print_mismatch_result(result, label) @stdout.puts "FAIL #{label}" @stdout.puts " expected #{result.expected_sha256}" @stdout.puts " actual #{result.actual_sha256}" end |
#print_ok_result(result, label, lockfile_mode) ⇒ Object
Prints a successful verification result.
30 31 32 33 34 35 |
# File 'lib/gem/guardian/result_printer.rb', line 30 def print_ok_result(result, label, lockfile_mode) prefix = lockfile_mode && result.checksum_source == :rubygems ? "FALLBACK" : "PASS" @stdout.puts "#{prefix} #{label}" @stdout.puts " sha256 #{result.actual_sha256}" @stdout.puts " source #{result.checksum_source}" if lockfile_mode && result.checksum_source end |
#print_result(result, lockfile_mode:) ⇒ Object
Prints one verification result.
20 21 22 23 24 25 26 27 |
# File 'lib/gem/guardian/result_printer.rb', line 20 def print_result(result, lockfile_mode:) label = result_label(result) case result.status when :ok then print_ok_result(result, label, lockfile_mode) when :mismatch then print_mismatch_result(result, label) else print_error_result(result, label) end end |
#print_results(results, lockfile_mode:) ⇒ Object
Prints a collection of verification results.
13 14 15 16 17 |
# File 'lib/gem/guardian/result_printer.rb', line 13 def print_results(results, lockfile_mode:) results.each do |result| print_result(result, lockfile_mode:) end end |
#usage ⇒ Object
Prints the CLI usage text.
62 63 64 |
# File 'lib/gem/guardian/result_printer.rb', line 62 def usage @stdout.puts(USAGE) end |