Class: Reviewer::Command
- Inherits:
-
Object
- Object
- Reviewer::Command
- Includes:
- Conversions
- Defined in:
- lib/reviewer/command.rb,
lib/reviewer/command/string.rb,
lib/reviewer/command/string/env.rb,
lib/reviewer/command/string/flags.rb more...
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 ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(tool, type) ⇒ Command
constructor
Creates an instance of the Command class to synthesize a command string using the tool, command type, and verbosity.
-
#raw_string ⇒ type
The raw command string before any substitutions.
-
#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.
-
#string ⇒ String
(also: #to_s)
The final command string with all of the conditions appled.
Methods included from Conversions
Constructor Details
permalink #initialize(tool, type) ⇒ Command
Creates an instance of the Command class to synthesize a command string using the tool, command type, and verbosity.
22 23 24 25 |
# File 'lib/reviewer/command.rb', line 22 def initialize(tool, type) @tool = Tool(tool) @type = type.to_sym end |
Instance Attribute Details
permalink #tool ⇒ Object (readonly)
Returns the value of attribute tool.
12 13 14 |
# File 'lib/reviewer/command.rb', line 12 def tool @tool end |
permalink #type ⇒ Object
Returns the value of attribute type.
14 15 16 |
# File 'lib/reviewer/command.rb', line 14 def type @type end |
Instance Method Details
permalink #raw_string ⇒ type
The raw command string before any substitutions. For example, since seeds need to remain consistent from one run to the next, they’re
54 55 56 |
# File 'lib/reviewer/command.rb', line 54 def raw_string @raw_string ||= String.new(type, tool_settings: tool.settings).to_s end |
permalink #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.
41 42 43 44 45 46 47 48 |
# File 'lib/reviewer/command.rb', line 41 def seed @seed ||= Random.rand(100_000) # Store the seed for reference Reviewer.history.set(tool.key, :last_seed, @seed) @seed end |
permalink #string ⇒ String Also known as: to_s
The final command string with all of the conditions appled
30 31 32 |
# File 'lib/reviewer/command.rb', line 30 def string @string ||= seed_substitution? ? seeded_string : raw_string end |