Class: Reviewer::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/batch.rb,
lib/reviewer/batch/formatter.rb

Overview

Provides a structure for running commands for a given set of tools

Defined Under Namespace

Classes: Formatter, UnrecognizedCommandError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_type, tools, strategy:, context:) ⇒ self

Generates an instance of Batch for running multiple tools together

Parameters:

  • command_type (Symbol)

    the type of command to run for each tool.

  • tools (Array<Tool>)

    the tools to run the commands for

  • strategy (Class)

    the runner strategy class (Captured or Passthrough)

  • context (Context)

    the shared runtime dependencies (arguments, output, history)



21
22
23
24
25
26
27
# File 'lib/reviewer/batch.rb', line 21

def initialize(command_type, tools, strategy:, context:)
  @command_type = command_type
  @tools = tools
  @strategy = strategy
  @context = context
  @report = Report.new
end

Instance Attribute Details

#command_typeObject (readonly)

Returns the value of attribute command_type.



11
12
13
# File 'lib/reviewer/batch.rb', line 11

def command_type
  @command_type
end

#reportObject (readonly)

Returns the value of attribute report.



11
12
13
# File 'lib/reviewer/batch.rb', line 11

def report
  @report
end

#toolsObject (readonly)

Returns the value of attribute tools.



11
12
13
# File 'lib/reviewer/batch.rb', line 11

def tools
  @tools
end

Instance Method Details

#runReport

Iterates over the tools in the batch to successfully run the commands. Also times the entire

batch in order to provide a total execution time.

Returns:

  • (Report)

    the report containing results for all commands run



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/reviewer/batch.rb', line 33

def run
  elapsed_time = Benchmark.realtime do
    clear_last_statuses
    matching_tools.each do |tool|
      runner = run_tool(tool)
      break unless runner.success? || runner.missing?
    end
  end

  @report.record_duration(elapsed_time)
  @report
end