Class: Reviewer::Command::String

Inherits:
Object
  • Object
show all
Includes:
Reviewer::Conversions
Defined in:
lib/reviewer/command/string.rb,
lib/reviewer/command/string/env.rb,
lib/reviewer/command/string/flags.rb
more...

Overview

Assembles tool tool_settings into a usable command string for the command type

Defined Under Namespace

Classes: Env, Flags

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Reviewer::Conversions

Tool

Constructor Details

#initialize(command_type, tool_settings:) ⇒ String

Returns a new instance of String.

[View source]

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

def initialize(command_type, tool_settings:)
  @command_type = command_type
  @tool_settings = tool_settings
end

Instance Attribute Details

#command_typeObject (readonly)

Returns the value of attribute command_type.


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

def command_type
  @command_type
end

#tool_settingsObject (readonly)

Returns the value of attribute tool_settings.


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

def tool_settings
  @tool_settings
end

Instance Method Details

#bodyObject

[View source]

41
42
43
# File 'lib/reviewer/command/string.rb', line 41

def body
  tool_settings.commands.fetch(command_type)
end

#env_variablesString

The string of environment variables built from a tool’s configuration settings

Returns:

  • (String)

    the environment variable names and values concatened for the command

[View source]

37
38
39
# File 'lib/reviewer/command/string.rb', line 37

def env_variables
  Env.new(tool_settings.env).to_s
end

#flagsString

Gets the flags to be used in conjunction with the review command for a tool

1. The `review` commands are the only commands that use flags
2. If no flags are configured, this won't do anything

Returns:

  • (String)

    the concatenated list of flags to pass to the review command

[View source]

50
51
52
53
54
# File 'lib/reviewer/command/string.rb', line 50

def flags
  return nil unless flags?

  Flags.new(tool_settings.flags).to_s
end

#to_aObject

[View source]

26
27
28
29
30
31
32
# File 'lib/reviewer/command/string.rb', line 26

def to_a
  [
    env_variables,
    body,
    flags
  ].compact
end

#to_sObject

[View source]

19
20
21
22
23
24
# File 'lib/reviewer/command/string.rb', line 19

def to_s
  to_a
    .map(&:strip) # Remove extra spaces on the components
    .join(' ')    # Merge the components
    .strip        # Strip extra spaces from the end result
end