Class: Reviewer::Tool
- Inherits:
-
Object
- Object
- Reviewer::Tool
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/reviewer/tool.rb,
lib/reviewer/tool/timing.rb,
lib/reviewer/tool/settings.rb,
lib/reviewer/tool/conversions.rb,
lib/reviewer/tool/file_resolver.rb,
lib/reviewer/tool/test_file_mapper.rb
Overview
Provides an instance of a specific tool for accessing its settings and run history
Defined Under Namespace
Modules: Conversions Classes: FileResolver, Settings, TestFileMapper, Timing
Constant Summary collapse
- SIX_HOURS_IN_SECONDS =
Timing::SIX_HOURS_IN_SECONDS
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#command?(command_type) ⇒ Boolean
Determines whether a tool has a specific command type configured.
-
#eql?(other) ⇒ Boolean
(also: #==)
Determines if two tools are equal.
-
#formattable? ⇒ Boolean
Determines if the tool can run a
formatcommand. -
#initialize(tool_key, config:, history:) ⇒ Tool
constructor
Create an instance of a tool.
-
#install_command ⇒ String?
Returns the install command string for this tool.
-
#install_link ⇒ String?
Returns the text for the install link if available.
-
#install_link? ⇒ Boolean
Convenience method for determining if a tool has a configured install link.
-
#installable? ⇒ Boolean
Determines if the tool can run a
installcommand. -
#matches_tags?(tag_list) ⇒ Boolean
Whether this tool matches any of the given tags and is eligible for batch runs.
-
#preparable? ⇒ Boolean
Determines if the tool can run a
preparecommand. -
#prepare? ⇒ Boolean
For determining if the tool should run its preparation command.
-
#record_run(result) ⇒ void
Records the pass/fail status and failed files from a result into history.
-
#resolve_files(files) ⇒ Array<String>
Resolves which files this tool should process.
-
#reviewable? ⇒ Boolean
Determines if the tool can run a
reviewcommand. -
#skip_files?(files) ⇒ Boolean
Determines if this tool should be skipped because files were requested but none match.
-
#stale? ⇒ Boolean
Determines whether the
preparecommand was run recently enough. -
#to_s ⇒ String
Returns the tool’s name as a string.
-
#to_sym ⇒ Symbol
Returns the tool’s key as a symbol.
Constructor Details
#initialize(tool_key, config:, history:) ⇒ Tool
Create an instance of a tool
47 48 49 50 51 |
# File 'lib/reviewer/tool.rb', line 47 def initialize(tool_key, config:, history:) @settings = Settings.new(tool_key, config: config) @history = history @timing = Timing.new(history, key) end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
17 18 19 |
# File 'lib/reviewer/tool.rb', line 17 def settings @settings end |
Instance Method Details
#command?(command_type) ⇒ Boolean
Determines whether a tool has a specific command type configured
64 65 66 |
# File 'lib/reviewer/tool.rb', line 64 def command?(command_type) commands.key?(command_type) && commands[command_type] end |
#eql?(other) ⇒ Boolean Also known as: ==
Determines if two tools are equal
134 135 136 |
# File 'lib/reviewer/tool.rb', line 134 def eql?(other) settings == other.settings end |
#formattable? ⇒ Boolean
Determines if the tool can run a format command
93 |
# File 'lib/reviewer/tool.rb', line 93 def formattable? = command?(:format) |
#install_command ⇒ String?
Returns the install command string for this tool
76 77 78 |
# File 'lib/reviewer/tool.rb', line 76 def install_command commands[:install] end |
#install_link ⇒ String?
Returns the text for the install link if available
128 |
# File 'lib/reviewer/tool.rb', line 128 def install_link = install_link? ? links.fetch(:install) : nil |
#install_link? ⇒ Boolean
Convenience method for determining if a tool has a configured install link
123 |
# File 'lib/reviewer/tool.rb', line 123 def install_link? = links.key?(:install) && !!links[:install] |
#installable? ⇒ Boolean
Determines if the tool can run a install command
71 |
# File 'lib/reviewer/tool.rb', line 71 def installable? = command?(:install) |
#matches_tags?(tag_list) ⇒ Boolean
Whether this tool matches any of the given tags and is eligible for batch runs
99 100 101 |
# File 'lib/reviewer/tool.rb', line 99 def (tag_list) !skip_in_batch? && tag_list.intersect?() end |
#preparable? ⇒ Boolean
Determines if the tool can run a prepare command
83 |
# File 'lib/reviewer/tool.rb', line 83 def preparable? = command?(:prepare) |
#prepare? ⇒ Boolean
For determining if the tool should run its preparation command. It will only be run if the tool has a preparation command and it hasn’t been run in the last 6 hours
58 |
# File 'lib/reviewer/tool.rb', line 58 def prepare? = preparable? && stale? |
#record_run(result) ⇒ void
This method returns an undefined value.
Records the pass/fail status and failed files from a result into history
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/reviewer/tool.rb', line 143 def record_run(result) status = result.success? ? :passed : :failed @history.set(key, :last_status, status) if result.success? @history.set(key, :last_failed_files, nil) else files = Runner::FailedFiles.new(result.stdout, result.stderr).to_a @history.set(key, :last_failed_files, files) if files.any? end end |
#resolve_files(files) ⇒ Array<String>
Resolves which files this tool should process
159 160 161 |
# File 'lib/reviewer/tool.rb', line 159 def resolve_files(files) file_resolver.resolve(files) end |
#reviewable? ⇒ Boolean
Determines if the tool can run a review command
88 |
# File 'lib/reviewer/tool.rb', line 88 def reviewable? = command?(:review) |
#skip_files?(files) ⇒ Boolean
Determines if this tool should be skipped because files were requested but none match
167 168 169 |
# File 'lib/reviewer/tool.rb', line 167 def skip_files?(files) file_resolver.skip?(files) end |
#stale? ⇒ Boolean
Determines whether the prepare command was run recently enough
114 115 116 117 118 |
# File 'lib/reviewer/tool.rb', line 114 def stale? return false unless preparable? @timing.stale? end |
#to_s ⇒ String
Returns the tool’s name as a string
39 |
# File 'lib/reviewer/tool.rb', line 39 def to_s = name |
#to_sym ⇒ Symbol
Returns the tool’s key as a symbol
35 |
# File 'lib/reviewer/tool.rb', line 35 def to_sym = key |