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
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
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
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
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
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
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
Private Instance Methods
# File lib/reviewer/tools.rb, line 77 def configured @configured ||= Loader.configuration end
# File lib/reviewer/tools.rb, line 93 def named?(tool) tool_names.map(&:to_s).include?(tool.key.to_s) end
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
# File lib/reviewer/tools.rb, line 89 def tagged?(tool) tool.enabled? && (tags & tool.tags).any? end
# File lib/reviewer/tools.rb, line 85 def tool_names Array(@tool_names || Reviewer.arguments.keywords.for_tool_names) end