class Reviewer::Tools

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

Public Class Methods

new(tags: nil, tool_names: nil) click to toggle source

Provides an instance to work with for knowing which tools to run in a given context. @param tags: nil [Array] the tags to use to filter tools for a run @param tool_names: nil [type] the explicitly provided tool names to filter tools for a run

@return [Reviewer::Tools] collection of tools based on the current run context

# File lib/reviewer/tools.rb, line 14
def initialize(tags: nil, tool_names: nil)
  @tags       = tags
  @tool_names = tool_names
end

Public Instance Methods

all() click to toggle source

Provides a collection of all configured tools instantiated as Tool instances

@return [Array<Tool>] the full collection of all Tool instances

# File lib/reviewer/tools.rb, line 30
def all
  configured.keys.map { |tool_name| Tool.new(tool_name) }
end
Also aliased as: to_a
current() click to toggle source

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.

@return [Array<Tool>] the full collection of should-be-used-for-this-run tools

# File lib/reviewer/tools.rb, line 62
def current
  subset? ? (specified + tagged).uniq : enabled
end
enabled() click to toggle source

Provides a collection of all enabled tools instantiated as Tool instances

@return [Array<Tool>] the full collection of all enabled Tool instances

# File lib/reviewer/tools.rb, line 38
def enabled
  @enabled ||= all.keep_if(&:enabled?)
end
inspect()
Alias for: to_h
specified() click to toggle source

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

@return [Array<Tool>] the full collection of explicitly-specified tools for a run

# File lib/reviewer/tools.rb, line 45
def specified
  all.keep_if { |tool| named?(tool) }
end
tagged() click to toggle source

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

@return [Array<Tool>] the full collection of tagged-via-command-line tools for a run

# File lib/reviewer/tools.rb, line 52
def tagged
  enabled.keep_if { |tool| tagged?(tool) }
end
to_a()
Alias for: all
to_h() click to toggle source

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

@return [Hash] hash representing all of the configured tools

# File lib/reviewer/tools.rb, line 22
def to_h
  configured
end
Also aliased as: inspect

Private Instance Methods

configured() click to toggle source
# File lib/reviewer/tools.rb, line 77
def configured
  @configured ||= Loader.configuration
end
named?(tool) click to toggle source
# File lib/reviewer/tools.rb, line 93
def named?(tool)
  tool_names.map(&:to_s).include?(tool.key.to_s)
end
subset?() click to toggle source

Determines if the current run should include a subset of a tools or the full suite of enabled tools by determining if any tool names or tags were provided that would reduce the full set to only a subset of relevant tools.

@return [Boolean] true if any tool names or tags are provided via the command line

# File lib/reviewer/tools.rb, line 73
def subset?
  tool_names.any? || tags.any?
end
tagged?(tool) click to toggle source
# File lib/reviewer/tools.rb, line 89
def tagged?(tool)
  tool.enabled? && (tags & tool.tags).any?
end
tags() click to toggle source
# File lib/reviewer/tools.rb, line 81
def tags
  Array(@tags || Reviewer.arguments.tags)
end
tool_names() click to toggle source
# File lib/reviewer/tools.rb, line 85
def tool_names
  Array(@tool_names || Reviewer.arguments.keywords.for_tool_names)
end