Class: Reviewer::Command
- Inherits:
-
Object
- Object
- Reviewer::Command
- Includes:
- Tool::Conversions
- Defined in:
- lib/reviewer/command.rb,
lib/reviewer/command/string.rb,
lib/reviewer/command/string/env.rb,
lib/reviewer/command/string/flags.rb
Overview
The core funtionality to translate a tool, command type, and verbosity into a runnable command
Defined Under Namespace
Classes: String
Constant Summary collapse
- SEED_SUBSTITUTION_VALUE =
'$SEED'
Instance Attribute Summary collapse
-
#tool ⇒ Object
readonly
Returns the value of attribute tool.
-
#type ⇒ Symbol
The command type (:install, :prepare, :review, :format).
Instance Method Summary collapse
-
#initialize(tool, type, context:) ⇒ Command
constructor
Creates an instance of the Command class to synthesize a command string using the tool, command type, and verbosity.
-
#raw_string ⇒ String
The raw command string before any substitutions.
-
#run_summary ⇒ Hash?
Returns a summary hash for run display, or nil if this command should be skipped.
-
#seed ⇒ Integer
Generates a seed that can be re-used across runs so that the results are consistent across related runs for tools that would otherwise change the seed automatically every run.
-
#skip? ⇒ Boolean
Determines if this command should be skipped because files were requested but none match.
-
#string ⇒ String
(also: #to_s)
The final command string with all of the conditions appled.
-
#target_files ⇒ Array<String>
Gets the list of files to target for this command, resolved by the tool.
Methods included from Tool::Conversions
Constructor Details
#initialize(tool, type, context:) ⇒ Command
Creates an instance of the Command class to synthesize a command string using the tool, command type, and verbosity.
26 27 28 29 30 31 32 |
# File 'lib/reviewer/command.rb', line 26 def initialize(tool, type, context:) @tool = Tool(tool) @type = type.to_sym @seed = nil @arguments = context.arguments @history = context.history end |
Instance Attribute Details
#tool ⇒ Object (readonly)
Returns the value of attribute tool.
12 13 14 |
# File 'lib/reviewer/command.rb', line 12 def tool @tool end |
#type ⇒ Symbol
Returns the command type (:install, :prepare, :review, :format).
17 18 19 |
# File 'lib/reviewer/command.rb', line 17 def type @type end |
Instance Method Details
#raw_string ⇒ String
The raw command string before any substitutions. For example, since seeds need to remain consistent from one run to the next, they’re
65 66 67 |
# File 'lib/reviewer/command.rb', line 65 def raw_string @raw_string ||= String.new(type, tool_settings: tool.settings, files: target_files).to_s # rubocop:disable Lint/RedundantTypeConversion end |
#run_summary ⇒ Hash?
Returns a summary hash for run display, or nil if this command should be skipped
86 87 88 89 90 |
# File 'lib/reviewer/command.rb', line 86 def run_summary return nil if skip? { name: tool.name, files: target_files } end |
#seed ⇒ Integer
Generates a seed that can be re-used across runs so that the results are consistent across related runs for tools that would otherwise change the seed automatically every run. Since not all tools will use the seed, there’s no need to generate it in the initializer. Instead, it’s memoized if it’s used.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/reviewer/command.rb', line 48 def seed @seed ||= if arguments.keywords.failed? history.get(tool.key, :last_seed) || Random.rand(100_000) else Random.rand(100_000) end # Store the seed for reference history.set(tool.key, :last_seed, @seed) @seed end |
#skip? ⇒ Boolean
Determines if this command should be skipped because files were requested but none match
79 80 81 |
# File 'lib/reviewer/command.rb', line 79 def skip? tool.skip_files?(requested_files) end |
#string ⇒ String Also known as: to_s
The final command string with all of the conditions appled
37 38 39 |
# File 'lib/reviewer/command.rb', line 37 def string @string ||= seed_substitution? ? seeded_string : raw_string end |
#target_files ⇒ Array<String>
Gets the list of files to target for this command, resolved by the tool
72 73 74 |
# File 'lib/reviewer/command.rb', line 72 def target_files @target_files ||= tool.resolve_files(requested_files) end |