class Reviewer::Shell

Handles running, timing, and capturing results for a command

Attributes

result[R]
timer[R]

Public Class Methods

new() click to toggle source

Initializes a Reviewer shell for running and benchmarking commands, and capturing output

@return [Shell] a shell instance for running and benchmarking commands

# File lib/reviewer/shell.rb, line 20
def initialize
  @timer = Timer.new
  @result = Result.new
end

Public Instance Methods

capture_main(command) click to toggle source
# File lib/reviewer/shell.rb, line 39
def capture_main(command)
  timer.record_main { capture_results(command) }
end
capture_prep(command) click to toggle source
# File lib/reviewer/shell.rb, line 35
def capture_prep(command)
  timer.record_prep { capture_results(command) }
end
direct(command) click to toggle source

Run a command without capturing the output. This ensures the results are displayed the same as if the command was run directly in the shell. So it keeps any color or other formatting that would be stripped out by capturing $stdout as a basic string. @param command [String] the command to run

@return [Integer] exit status vaue of 0 when successful or 1 when unsuccessful

# File lib/reviewer/shell.rb, line 31
def direct(command)
  result.exit_status = print_results(command) ? 0 : 1
end

Private Instance Methods

capture_results(command) click to toggle source
# File lib/reviewer/shell.rb, line 45
def capture_results(command)
  command = String(command)

  captured_results = Open3.capture3(command)
  @result = Result.new(*captured_results)
end
print_results(command) click to toggle source