class Reviewer::Batch
Provides a structure for running commands for a given set of tools
Attributes
command_type[R]
output[R]
results[R]
tools[R]
Public Class Methods
new(command_type, tools, output: Reviewer.output)
click to toggle source
# File lib/reviewer/batch.rb, line 10 def initialize(command_type, tools, output: Reviewer.output) @command_type = command_type @tools = tools @output = output @results = {} end
run(*args)
click to toggle source
# File lib/reviewer/batch.rb, line 37 def self.run(*args) new(*args).run end
Public Instance Methods
run()
click to toggle source
# File lib/reviewer/batch.rb, line 17 def run benchmark_batch do tools.each do |tool| runner = Runner.new(tool, command_type, strategy) # With multiple tools, run each one quietly. # Otherwise, with just one tool runner.run # Record the exit status capture_results(runner) # If the tool fails, stop running other tools break unless runner.success? end end results end
Private Instance Methods
benchmark_batch(&block)
click to toggle source
Records and prints the total runtime of a block @param &block [type] section of code to be timed
@return [void] prints the elapsed time
# File lib/reviewer/batch.rb, line 59 def benchmark_batch(&block) elapsed_time = Benchmark.realtime(&block) output.info "\nTotal Time ".white + "#{elapsed_time.round(1)}s".bold end
capture_results(runner)
click to toggle source
# File lib/reviewer/batch.rb, line 51 def capture_results(runner) @results[runner.tool.key] = runner.exit_status end
multiple_tools?()
click to toggle source
# File lib/reviewer/batch.rb, line 43 def multiple_tools? tools.size > 1 end
strategy()
click to toggle source
# File lib/reviewer/batch.rb, line 47 def strategy multiple_tools? ? Runner::Strategies::Quiet : Runner::Strategies::Verbose end