Class: Reviewer::Tool

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/reviewer/tool.rb,
lib/reviewer/tool/timing.rb,
lib/reviewer/tool/settings.rb,
lib/reviewer/tool/conversions.rb,
lib/reviewer/tool/file_resolver.rb,
lib/reviewer/tool/test_file_mapper.rb

Overview

Provides an instance of a specific tool for accessing its settings and run history

Defined Under Namespace

Modules: Conversions Classes: FileResolver, Settings, TestFileMapper, Timing

Constant Summary collapse

SIX_HOURS_IN_SECONDS =
Timing::SIX_HOURS_IN_SECONDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_key, config:, history:) ⇒ Tool

Create an instance of a tool

Parameters:

  • tool_key (Symbol)

    the key to the tool from the configuration file

  • config (Hash)

    the tool’s configuration hash

  • history (History)

    the history store for timing and state persistence



47
48
49
50
51
# File 'lib/reviewer/tool.rb', line 47

def initialize(tool_key, config:, history:)
  @settings = Settings.new(tool_key, config: config)
  @history = history
  @timing = Timing.new(history, key)
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



17
18
19
# File 'lib/reviewer/tool.rb', line 17

def settings
  @settings
end

Instance Method Details

#command?(command_type) ⇒ Boolean

Determines whether a tool has a specific command type configured

Parameters:

  • command_type (Symbol)

    one of the available command types defined in Command::TYPES

Returns:

  • (Boolean)

    true if the command type is configured and not blank



64
65
66
# File 'lib/reviewer/tool.rb', line 64

def command?(command_type)
  commands.key?(command_type) && commands[command_type]
end

#eql?(other) ⇒ Boolean Also known as: ==

Determines if two tools are equal

Parameters:

  • other (Tool)

    the tool to compare to the current instance

Returns:

  • (Boolean)

    true if the settings match



134
135
136
# File 'lib/reviewer/tool.rb', line 134

def eql?(other)
  settings == other.settings
end

#formattable?Boolean

Determines if the tool can run a format command

Returns:

  • (Boolean)

    true if there is a non-blank format command configured



93
# File 'lib/reviewer/tool.rb', line 93

def formattable? = command?(:format)

#install_commandString?

Returns the install command string for this tool

Returns:

  • (String, nil)

    the install command or nil if not configured



76
77
78
# File 'lib/reviewer/tool.rb', line 76

def install_command
  commands[:install]
end

Returns the text for the install link if available

Returns:

  • (String, nil)

    the link if it exists, nil otherwise



128
# File 'lib/reviewer/tool.rb', line 128

def install_link = install_link? ? links.fetch(:install) : nil

#install_link?Boolean

Convenience method for determining if a tool has a configured install link

Returns:

  • (Boolean)

    true if there is an install key under links and the value isn’t blank



123
# File 'lib/reviewer/tool.rb', line 123

def install_link? = links.key?(:install) && !!links[:install]

#installable?Boolean

Determines if the tool can run a install command

Returns:

  • (Boolean)

    true if there is a non-blank install command configured



71
# File 'lib/reviewer/tool.rb', line 71

def installable? = command?(:install)

#matches_tags?(tag_list) ⇒ Boolean

Whether this tool matches any of the given tags and is eligible for batch runs

Parameters:

  • tag_list (Array<String, Symbol>)

    tags to match against

Returns:

  • (Boolean)

    true if the tool is batch-eligible and shares at least one tag



99
100
101
# File 'lib/reviewer/tool.rb', line 99

def matches_tags?(tag_list)
  !skip_in_batch? && tag_list.intersect?(tags)
end

#preparable?Boolean

Determines if the tool can run a prepare command

Returns:

  • (Boolean)

    true if there is a non-blank prepare command configured



83
# File 'lib/reviewer/tool.rb', line 83

def preparable? = command?(:prepare)

#prepare?Boolean

For determining if the tool should run its preparation command. It will only be run if the tool has a preparation command and it hasn’t been run in the last 6 hours

Returns:

  • (Boolean)

    true if the tool has a configured prepare command that hasn’t been run in the last 6 hours



58
# File 'lib/reviewer/tool.rb', line 58

def prepare? = preparable? && stale?

#record_run(result) ⇒ void

This method returns an undefined value.

Records the pass/fail status and failed files from a result into history

Parameters:



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/reviewer/tool.rb', line 143

def record_run(result)
  status = result.success? ? :passed : :failed
  @history.set(key, :last_status, status)

  if result.success?
    @history.set(key, :last_failed_files, nil)
  else
    files = Runner::FailedFiles.new(result.stdout, result.stderr).to_a
    @history.set(key, :last_failed_files, files) if files.any?
  end
end

#resolve_files(files) ⇒ Array<String>

Resolves which files this tool should process

Parameters:

  • files (Array<String>)

    the input files to resolve

Returns:

  • (Array<String>)

    files after mapping and filtering



159
160
161
# File 'lib/reviewer/tool.rb', line 159

def resolve_files(files)
  file_resolver.resolve(files)
end

#reviewable?Boolean

Determines if the tool can run a review command

Returns:

  • (Boolean)

    true if there is a non-blank review command configured



88
# File 'lib/reviewer/tool.rb', line 88

def reviewable? = command?(:review)

#skip_files?(files) ⇒ Boolean

Determines if this tool should be skipped because files were requested but none match

Parameters:

  • files (Array<String>)

    the requested files

Returns:

  • (Boolean)

    true if files were requested but none match after resolution



167
168
169
# File 'lib/reviewer/tool.rb', line 167

def skip_files?(files)
  file_resolver.skip?(files)
end

#stale?Boolean

Determines whether the prepare command was run recently enough

Returns:

  • (Boolean)

    true if a prepare command exists, a timestamp exists, and it was run more than six hours ago



114
115
116
117
118
# File 'lib/reviewer/tool.rb', line 114

def stale?
  return false unless preparable?

  @timing.stale?
end

#to_sString

Returns the tool’s name as a string

Returns:

  • (String)

    the tool’s display name



39
# File 'lib/reviewer/tool.rb', line 39

def to_s = name

#to_symSymbol

Returns the tool’s key as a symbol

Returns:

  • (Symbol)

    the tool’s unique identifier



35
# File 'lib/reviewer/tool.rb', line 35

def to_sym = key