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) ⇒ Reviewer::Tools

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

Parameters:

  • tags: (defaults to: nil)

    nil [Array] the tags to use to filter tools for a run

  • tool_names: (defaults to: nil)

    nil [type] the explicitly provided tool names to filter tools for a run

[View source]

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

def initialize(tags: nil, tool_names: nil)
  @tags       = tags
  @tool_names = tool_names
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

[View source]

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

def all
  configured.keys.map { |tool_name| Tool.new(tool_name) }
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, 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

[View source]

62
63
64
# File 'lib/reviewer/tools.rb', line 62

def current
  subset? ? (specified + tagged).uniq : enabled
end

#enabledArray<Tool>

Provides a collection of all enabled tools instantiated as Tool instances

Returns:

  • (Array<Tool>)

    the full collection of all enabled Tool instances

[View source]

38
39
40
# File 'lib/reviewer/tools.rb', line 38

def enabled
  @enabled ||= all.keep_if(&:enabled?)
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

[View source]

45
46
47
# File 'lib/reviewer/tools.rb', line 45

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

[View source]

52
53
54
# File 'lib/reviewer/tools.rb', line 52

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

[View source]

22
23
24
# File 'lib/reviewer/tools.rb', line 22

def to_h
  configured
end