Class: Reviewer::Shell

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/reviewer/shell.rb,
lib/reviewer/shell/timer.rb,
lib/reviewer/shell/result.rb

Overview

Handles running, timing, and capturing results for a command

Defined Under Namespace

Classes: Result, Timer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShell

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



20
21
22
23
# File 'lib/reviewer/shell.rb', line 20

def initialize
  @timer = Timer.new
  @result = Result.new
end

Instance Attribute Details

#captured_resultsObject (readonly)

Returns the value of attribute captured_results.



13
14
15
# File 'lib/reviewer/shell.rb', line 13

def captured_results
  @captured_results
end

#resultObject (readonly)

Returns the value of attribute result.



13
14
15
# File 'lib/reviewer/shell.rb', line 13

def result
  @result
end

#timerObject (readonly)

Returns the value of attribute timer.



13
14
15
# File 'lib/reviewer/shell.rb', line 13

def timer
  @timer
end

Instance Method Details

#capture_main(command) ⇒ Object



41
42
43
# File 'lib/reviewer/shell.rb', line 41

def capture_main(command)
  timer.record_main { capture_results(command) }
end

#capture_prep(command) ⇒ Object



37
38
39
# File 'lib/reviewer/shell.rb', line 37

def capture_prep(command)
  timer.record_prep { capture_results(command) }
end

#direct(command) ⇒ Integer

Run a command without capturing the output. This ensures the results are displayed realtime 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.

Parameters:

  • command (String)

    the command to run

Returns:

  • (Integer)

    exit status vaue of 0 when successful or 1 when unsuccessful



31
32
33
34
35
# File 'lib/reviewer/shell.rb', line 31

def direct(command)
  command = String(command)

  result.exit_status = system(command) ? 0 : 1
end