class Reviewer::Command::String

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

Attributes

command_type[R]
tool_settings[R]
verbosity[R]

Public Class Methods

new(command_type, tool_settings:, verbosity: nil) click to toggle source
# File lib/reviewer/command/string.rb, line 15
def initialize(command_type, tool_settings:, verbosity: nil)
  @command_type = command_type
  @tool_settings = tool_settings
  @verbosity = Verbosity(verbosity)
end

Public Instance Methods

body() click to toggle source
# File lib/reviewer/command/string.rb, line 41
def body
  tool_settings.commands.fetch(command_type)
end
env_variables() click to toggle source
# File lib/reviewer/command/string.rb, line 37
def env_variables
  Env.new(tool_settings.env).to_s
end
flags() click to toggle source
# File lib/reviewer/command/string.rb, line 45
def flags
  # Flags to be used for `review` commands.
  # 1. The `review` commands are the only commands that use flags
  # 2. If no flags are configured, this won't do much
  #
  # Note: Since verbosity is handled separately, flags for 'quiet' are handled separately at a
  #   lower level by design and excluded from this check. They are not included with the other
  #   configured flags.
  return nil unless flags?

  Flags.new(tool_settings.flags).to_s
end
to_a() click to toggle source
# File lib/reviewer/command/string.rb, line 28
def to_a
  [
    env_variables,
    body,
    flags,
    verbosity_options
  ].compact
end
to_s() click to toggle source
# File lib/reviewer/command/string.rb, line 21
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
verbosity_options() click to toggle source
# File lib/reviewer/command/string.rb, line 58
def verbosity_options
  Verbosity.new(tool_settings.quiet_option, level: verbosity.level).to_s
end

Private Instance Methods

flags?() click to toggle source

Determines whether the string needs flags added

@return [Boolean] true if it's a review command and it has flags configured

# File lib/reviewer/command/string.rb, line 67
def flags?
  command_type == :review && tool_settings.flags.any?
end