Class: Reviewer::Runner::Strategies::Captured

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/runner/strategies/captured.rb

Overview

Execution strategy for a runner to run a command quietly by capturing the output and only

displaying it if there's a failure that justifies it

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner) ⇒ self

Create an instance of the captured strategy for a command runner so that any output is

fully suppressed so as to not create too much noise when running multiple commands.

Parameters:

  • runner (Runner)

    the instance of the runner to apply the strategy to


18
19
20
21
# File 'lib/reviewer/runner/strategies/captured.rb', line 18

def initialize(runner)
  @runner = runner
  @start_time = Time.now
end

Instance Attribute Details

#runnerRunner (readonly)

the instance of the runner that will be executed with this strategy

Returns:

  • (Runner)

    the current value of runner


10
11
12
# File 'lib/reviewer/runner/strategies/captured.rb', line 10

def runner
  @runner
end

#start_timeTime (readonly)

the start time for the strategy_for timing purposes

Returns:

  • (Time)

    the current value of start_time


10
11
12
# File 'lib/reviewer/runner/strategies/captured.rb', line 10

def start_time
  @start_time
end

Instance Method Details

#preparevoid

This method returns an undefined value.

The prepare command strategy when running a command and capturing the results


26
27
28
29
30
31
32
33
# File 'lib/reviewer/runner/strategies/captured.rb', line 26

def prepare
  command = runner.prepare_command

  display_progress(command) { runner.shell.capture_prep(command) }

  # Running the prepare command, so make sure the timestamp is updated
  runner.update_last_prepared_at
end

#runvoid

This method returns an undefined value.

The run command strategy when running a command and capturing the results


38
39
40
41
42
43
44
45
46
# File 'lib/reviewer/runner/strategies/captured.rb', line 38

def run
  command = runner.command

  display_progress(command) { runner.shell.capture_main(command) }

  # If it's successful, show that it was a success and how long it took to run, otherwise,
  # it wasn't successful and we got some explaining to do...
  runner.success? ? show_timing_result : show_command_output
end