Class: Reviewer::Runner
- Inherits:
-
Object
- Object
- Reviewer::Runner
- Extended by:
- Forwardable
- Defined in:
- lib/reviewer/runner.rb,
lib/reviewer/runner/strategies/captured.rb,
lib/reviewer/runner/strategies/passthrough.rb more...
Overview
Wrapper for executng a command and printing the results
Defined Under Namespace
Modules: Strategies
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
-
#strategy ⇒ Object
Returns the value of attribute strategy.
Instance Method Summary collapse
-
#execute_strategy ⇒ void
Runs the relevant strategy to either capture or pass through command output.
-
#guidance ⇒ Guidance
Uses the result of the runner to determine what, if any, guidance to display to help the user get back on track in the event of an unsuccessful run.
-
#identify_tool ⇒ void
Prints the tool name and description to the console as a frame of reference.
-
#initialize(tool, command_type, strategy = Strategies::Captured, output: Reviewer.output) ⇒ self
constructor
Creates a wrapper for running commansd through Reviewer in order to provide a more accessible API for recording execution time and interpreting the results of a command in a more generous way so that non-zero exit statuses can still potentiall be passing.
-
#prepare_command ⇒ Comman
Creates_an instance of the prepare command for a tool.
-
#record_timing ⇒ void
Saves the last 5 elapsed times for the commands used this run by using the raw command as a unique key.
- #run ⇒ Object
-
#run_prepare_step? ⇒ Boolean
Determines whether a preparation step should be run before the primary command.
- #success? ⇒ Boolean
-
#update_last_prepared_at ⇒ Time
Updates the ‘last prepared at’ timestamp that Reviewer uses to know if a tool’s preparation step is stale and needs to be run again.
Constructor Details
permalink #initialize(tool, command_type, strategy = Strategies::Captured, output: Reviewer.output) ⇒ self
Creates a wrapper for running commansd through Reviewer in order to provide a more accessible
API for recording execution time and interpreting the results of a command in a more
generous way so that non-zero exit statuses can still potentiall be passing.
29 30 31 32 33 34 |
# File 'lib/reviewer/runner.rb', line 29 def initialize(tool, command_type, strategy = Strategies::Captured, output: Reviewer.output) @command = Command.new(tool, command_type) @strategy = strategy @shell = Shell.new @output = output end |
Instance Attribute Details
permalink #command ⇒ Object (readonly)
Returns the value of attribute command.
13 14 15 |
# File 'lib/reviewer/runner.rb', line 13 def command @command end |
permalink #output ⇒ Object (readonly)
Returns the value of attribute output.
13 14 15 |
# File 'lib/reviewer/runner.rb', line 13 def output @output end |
permalink #shell ⇒ Object (readonly)
Returns the value of attribute shell.
13 14 15 |
# File 'lib/reviewer/runner.rb', line 13 def shell @shell end |
permalink #strategy ⇒ Object
Returns the value of attribute strategy.
11 12 13 |
# File 'lib/reviewer/runner.rb', line 11 def strategy @strategy end |
Instance Method Details
permalink #execute_strategy ⇒ void
This method returns an undefined value.
Runs the relevant strategy to either capture or pass through command output.
78 79 80 81 82 83 84 |
# File 'lib/reviewer/runner.rb', line 78 def execute_strategy # Run the provided strategy strategy.new(self).tap do |run_strategy| run_strategy.prepare if run_prepare_step? run_strategy.run end end |
permalink #guidance ⇒ Guidance
Uses the result of the runner to determine what, if any, guidance to display to help the user
get back on track in the event of an unsuccessful run.
127 128 129 |
# File 'lib/reviewer/runner.rb', line 127 def guidance @guidance ||= Reviewer::Guidance.new(command: command, result: result, output: output) end |
permalink #identify_tool ⇒ void
This method returns an undefined value.
Prints the tool name and description to the console as a frame of reference
67 68 69 70 71 72 73 |
# File 'lib/reviewer/runner.rb', line 67 def identify_tool # If there's an existing result, the runner is being re-run, and identifying the tool would # be redundant. return if result.exists? output.tool_summary(tool) end |
permalink #prepare_command ⇒ Comman
Creates_an instance of the prepare command for a tool
98 99 100 |
# File 'lib/reviewer/runner.rb', line 98 def prepare_command @prepare_command ||= Command.new(tool, :prepare) end |
permalink #record_timing ⇒ void
This method returns an undefined value.
Saves the last 5 elapsed times for the commands used this run by using the raw command as a
unique key. This enables the ability to compare times across runs while taking into
consideration that different iterations of the command may be running on fewer files. So
comparing a full run to the average time for a partial run wouldn't be helpful. By using the
raw command string, it will always be apples to apples.
118 119 120 121 |
# File 'lib/reviewer/runner.rb', line 118 def record_timing tool.record_timing(prepare_command, timer.prep) tool.record_timing(command, timer.main) end |
permalink #run ⇒ Object
[View source]
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/reviewer/runner.rb', line 36 def run # Show which tool is running identify_tool # Use the provided strategy to run the command execute_strategy # If it failed, display guidance to help them get back on track guidance.show unless success? # Return the exit status generated by the tool as interpreted by the Result exit_status end |
permalink #run_prepare_step? ⇒ Boolean
Determines whether a preparation step should be run before the primary command. If/when the
primary command is a `:prepare` command, then it shouldn't run twice. So it skips what would
be a superfluous run of the preparation.
91 92 93 |
# File 'lib/reviewer/runner.rb', line 91 def run_prepare_step? command.type != :prepare && tool.prepare? end |
permalink #success? ⇒ Boolean
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/reviewer/runner.rb', line 50 def success? # Some review tools return a range of non-zero exit statuses and almost never return 0. # (`yarn audit` is a good example.) Those tools can be configured to accept a non-zero exit # status so they aren't constantly considered to be failing over minor issues. # # But when other command types (prepare, install, format) are run, they either succeed or they # fail. With no shades of gray in those cases, anything other than a 0 is a failure. if command.type == :review exit_status <= tool.max_exit_status else exit_status.zero? end end |
permalink #update_last_prepared_at ⇒ Time
Updates the ‘last prepared at’ timestamp that Reviewer uses to know if a tool’s preparation
step is stale and needs to be run again.
106 107 108 109 |
# File 'lib/reviewer/runner.rb', line 106 def update_last_prepared_at # Touch the `last_prepared_at` timestamp for the tool so it waits before running again. tool.last_prepared_at = Time.now end |