Class: Reviewer::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/output.rb,
lib/reviewer/output/token.rb,
lib/reviewer/output/printer.rb,
lib/reviewer/output/scrubber.rb

Overview

Friendly API for printing nicely-formatted output to the console

Defined Under Namespace

Classes: Printer, Scrubber, Token

Constant Summary collapse

DEFAULT_CONSOLE_WIDTH =
120
DIVIDER =
'ยท'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(printer = Printer.new) ⇒ Output

Creates an instance of Output to print Reviewer activity and results to the console



18
19
20
# File 'lib/reviewer/output.rb', line 18

def initialize(printer = Printer.new)
  @printer = printer
end

Instance Attribute Details

#printerObject (readonly)

Returns the value of attribute printer.



15
16
17
# File 'lib/reviewer/output.rb', line 15

def printer
  @printer
end

Instance Method Details

#batch_summary(tool_count, seconds) ⇒ void

This method returns an undefined value.

Prints a summary of the total time and results for a batch run. If multiple tools, it will

show the total tool count

Parameters:

  • tool_count (Integer)

    the number of commands run in the batch

  • seconds (Float)

    the total number of seconds the batch ran in realtime



49
50
51
52
# File 'lib/reviewer/output.rb', line 49

def batch_summary(tool_count, seconds)
  printer.print(:bold, "~#{seconds.round(1)} seconds")
  printer.puts(:muted, " for #{tool_count} tools") if tool_count > 1
end

#clearObject



22
23
24
# File 'lib/reviewer/output.rb', line 22

def clear
  system('clear')
end

#current_command(command) ⇒ void

This method returns an undefined value.

Prints the text of a command to the console to help proactively expose potentials issues with

syntax if Reviewer translated thte provided options in an unexpected way

Parameters:

  • command (String, Command)

    the command to identify on the console



69
70
71
72
# File 'lib/reviewer/output.rb', line 69

def current_command(command)
  printer.puts(:bold, 'Now Running:')
  printer.puts(:default, String(command))
end

#dividerObject



30
31
32
33
# File 'lib/reviewer/output.rb', line 30

def divider
  newline
  printer.print(:muted, DIVIDER * console_width)
end

#failure(details, command: nil) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/reviewer/output.rb', line 82

def failure(details, command: nil)
  printer.print(:failure, 'Failure')
  printer.puts(:muted, " #{details}")

  return if command.nil?

  newline
  printer.puts(:bold, 'Failed Command:')
  printer.puts(:muted, String(command))
end

#guidance(summary, details) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/reviewer/output.rb', line 98

def guidance(summary, details)
  return if details.nil?

  newline
  printer.puts(:bold, summary)
  printer.puts(:muted, details)
end

#help(message) ⇒ void

This method returns an undefined value.

Prints plain text to the console

Parameters:

  • message (String)

    the text to write to the console



39
40
41
# File 'lib/reviewer/output.rb', line 39

def help(message)
  printer.puts(:default, message)
end

#newlineObject



26
27
28
# File 'lib/reviewer/output.rb', line 26

def newline
  printer.puts(:default, '')
end

#success(timer) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/reviewer/output.rb', line 74

def success(timer)
  printer.print(:success, 'Success')
  printer.print(:success_light, " #{timer.total_seconds}s")
  printer.print(:warning_light, " (#{timer.prep_percent}% prep ~#{timer.prep_seconds}s)") if timer.prepped?
  newline
  newline
end

#tool_summary(tool) ⇒ void

This method returns an undefined value.

Print a tool summary using the name and description. Used before running a command to help

identify which tool is running at any given moment.

Parameters:

  • tool (Tool)

    the tool to identify and describe



59
60
61
62
# File 'lib/reviewer/output.rb', line 59

def tool_summary(tool)
  printer.print(:bold, tool.name)
  printer.puts(:muted, " #{tool.description}")
end

#unfiltered(value) ⇒ Object



106
107
108
109
110
# File 'lib/reviewer/output.rb', line 106

def unfiltered(value)
  return if value.nil? || value.strip.empty?

  printer.stream << value
end

#unrecoverable(details) ⇒ Object



93
94
95
96
# File 'lib/reviewer/output.rb', line 93

def unrecoverable(details)
  printer.puts(:error, 'Unrecoverable Error:')
  printer.puts(:muted, details)
end