Class: Reviewer::Tools

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/reviewer/tools.rb

Overview

Provides convenient access to subsets of configured tools based on provided arguments, configured tools, their enabled/disabled status, and more.

Instance Method Summary collapse

Constructor Details

#initialize(tags: nil, tool_names: nil, arguments: nil, history: nil, config_file: nil) ⇒ Reviewer::Tools

Provides an instance to work with for knowing which tools to run in a given context.

Parameters:

  • tags (Array) (defaults to: nil)

    the tags to use to filter tools for a run

  • tool_names (Array<String>) (defaults to: nil)

    the explicitly provided tool names to filter tools for a run

  • arguments (Arguments) (defaults to: nil)

    the parsed CLI arguments

  • history (History) (defaults to: nil)

    the history store for status persistence

  • config_file (Pathname, nil) (defaults to: nil)

    path to the .reviewer.yml configuration file



17
18
19
20
21
22
23
# File 'lib/reviewer/tools.rb', line 17

def initialize(tags: nil, tool_names: nil, arguments: nil, history: nil, config_file: nil)
  @tags        = tags
  @tool_names  = tool_names
  @arguments   = arguments
  @history     = history
  @config_file = config_file
end

Instance Method Details

#allArray<Tool> Also known as: to_a

Provides a collection of all configured tools instantiated as Tool instances

Returns:

  • (Array<Tool>)

    the full collection of all Tool instances



34
35
36
# File 'lib/reviewer/tools.rb', line 34

def all
  configured.map { |tool_name, config| Tool.new(tool_name, config: config, history: @history) }
end

#currentArray<Tool>

Uses the full context of a run to provide the filtered subset of tools to use. It takes into consideration: tagged tools, explicitly-specified tools, failed tools, configuration (enabled/disabled), and any other relevant details that should influence whether a specific tool should be run as part of the current batch being executed.

Returns:

  • (Array<Tool>)

    the full collection of should-be-used-for-this-run tools



64
65
66
67
68
# File 'lib/reviewer/tools.rb', line 64

def current
  return enabled unless subset? || failed_keyword?

  (specified + tagged + failed).uniq
end

#enabledArray<Tool>

Provides a collection of all tools that run in the default batch

Returns:

  • (Array<Tool>)

    the full collection of batch-included Tool instances



42
# File 'lib/reviewer/tools.rb', line 42

def enabled = @enabled ||= all.reject(&:skip_in_batch?)

#failed_from_historyArray<Tool>

Returns tools that failed in the previous run based on history

Returns:

  • (Array<Tool>)

    tools with :last_status of :failed in history



73
74
75
# File 'lib/reviewer/tools.rb', line 73

def failed_from_history
  all.select { |tool| @history.get(tool.key, :last_status) == :failed }
end

#specifiedArray<Tool>

Provides a collection of all explicitly-specified-via-command-line tools as Tool instances

Returns:

  • (Array<Tool>)

    the full collection of explicitly-specified tools for a run



47
48
49
# File 'lib/reviewer/tools.rb', line 47

def specified
  all.keep_if { |tool| named?(tool) }
end

#taggedArray<Tool>

Provides a collection of all tagged-via-command-line tools as Tool instances

Returns:

  • (Array<Tool>)

    the full collection of tagged-via-command-line tools for a run



54
55
56
# File 'lib/reviewer/tools.rb', line 54

def tagged
  enabled.keep_if { |tool| tagged?(tool) }
end

#to_hHash Also known as: inspect

The current state of all available configured tools regardless of whether they are disabled

Returns:

  • (Hash)

    hash representing all of the configured tools



28
# File 'lib/reviewer/tools.rb', line 28

def to_h = configured