Class: Reviewer::Command

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Conversions

Tool

Constructor Details

#initialize(tool, type) ⇒ Command

Creates an instance of the Command class to synthesize a command string using the tool, command type, and verbosity.

Parameters:

  • tool (Tool, Symbol)

    a tool or tool key to use to look up the command and options

  • type (Symbol)

    the desired command type (:install, :prepare, :review, :format)

[View source]

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

#toolObject (readonly)

Returns the value of attribute tool.


12
13
14
# File 'lib/reviewer/command.rb', line 12

def tool
  @tool
end

#typeObject

Returns the value of attribute type.


14
15
16
# File 'lib/reviewer/command.rb', line 14

def type
  @type
end

Instance Method Details

#raw_stringtype

The raw command string before any substitutions. For example, since seeds need to remain consistent from one run to the next, they’re

Returns:

  • (type)
    description
[View source]

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

#seedInteger

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.

Returns:

  • (Integer)

    a random integer to pass to tools that use seeds

[View source]

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

#stringString Also known as: to_s

The final command string with all of the conditions appled

Returns:

  • (String)

    the final, valid command string to run

[View source]

30
31
32
# File 'lib/reviewer/command.rb', line 30

def string
  @string ||= seed_substitution? ? seeded_string : raw_string
end