class Reviewer::Arguments::Keywords

Handles interpreting all 'leftover' arguments and translating them to file-related, tag-related, or tool-related arguments

Constants

RESERVED

Attributes

provided[RW]
raw[RW]

Public Class Methods

new(*provided) click to toggle source

Generates an instace of parsed keywords from the provided arguments @param *provided [Array<String>] the leftover (non-flag) arguments from the command line

@return [Arguments::Keywords]

# File lib/reviewer/arguments/keywords.rb, line 18
def initialize(*provided)
  @provided = Array(provided.flatten)
end

Public Instance Methods

configured_tags() click to toggle source

Provides the complete list of all configured tags for enabled tools

@return [Array<String>] all unique configured tags

# File lib/reviewer/arguments/keywords.rb, line 98
def configured_tags
  tools.enabled.map(&:tags).flatten.uniq.sort
end
configured_tool_names() click to toggle source

Provides the complete list of all configured tool names for enabled tools

@return [Array<String>] all unique configured tools

# File lib/reviewer/arguments/keywords.rb, line 105
def configured_tool_names
  # We explicitly don't sort the tool names list because Reviewer uses the configuration order
  # to determine the execution order. So not sorting maintains the predicted order it will run
  # in and leaves the option to sort to the consuming code if needed
  tools.all.map { |tool| tool.key.to_s }
end
for_tags() click to toggle source

Extracts keywords that match configured tags for enabled tools

@return [Array<String>] intersection of provided arguments and configured tags for tools

# File lib/reviewer/arguments/keywords.rb, line 63
def for_tags
  intersection_with configured_tags
end
for_tool_names() click to toggle source

Extracts keywords that match configured tool keys

@return [Array<String>] intersection of provided arguments and configured tool names

# File lib/reviewer/arguments/keywords.rb, line 70
def for_tool_names
  intersection_with configured_tool_names
end
inspect()
Alias for: to_h
possible() click to toggle source

Provides the complete list of all recognized keywords based on configuration

@return [Array<String>] all keywords that Reviewer can recognized

# File lib/reviewer/arguments/keywords.rb, line 91
def possible
  (RESERVED + configured_tags + configured_tool_names).uniq.sort
end
recognized() click to toggle source

Extracts keywords that match any possible recognized keyword values

@return [Array<String>] intersection of provided arguments and recognizable keywords

# File lib/reviewer/arguments/keywords.rb, line 77
def recognized
  intersection_with possible
end
reserved() click to toggle source

Extracts reserved keywords from the provided arguments

@return [Array<String>] intersection of provided arguments and reserved keywords

# File lib/reviewer/arguments/keywords.rb, line 56
def reserved
  intersection_with RESERVED
end
to_a() click to toggle source

Proves the full list of raw keyword arguments explicitly passed via command-line as an array

@return [Array] full collection of the provided keyword arguments as a string

# File lib/reviewer/arguments/keywords.rb, line 25
def to_a
  provided
end
to_h() click to toggle source

Summary of the state of keyword arguments based on how Reviewer parsed them

@return [Hash] represents the summary of the keyword values parsed from the command-line and

grouped based on how they were parsed
# File lib/reviewer/arguments/keywords.rb, line 41
def to_h
  {
    provided: provided,
    recognized: recognized,
    unrecognized: unrecognized,
    reserved: reserved,
    for_tags: for_tags,
    for_tool_names: for_tool_names
  }
end
Also aliased as: inspect
to_s() click to toggle source

Provides the full list of raw keyword arguments explicitly passed via command-line as a

comma-separated string

@return [String] comma-separated list of the file arguments as a string

# File lib/reviewer/arguments/keywords.rb, line 33
def to_s
  to_a.join(',')
end
unrecognized() click to toggle source

Extracts keywords that don't match any possible recognized keyword values

@return [Array<String>] leftover keywords that weren't recognized

# File lib/reviewer/arguments/keywords.rb, line 84
def unrecognized
  (provided - recognized).uniq.sort
end

Private Instance Methods

intersection_with(values) click to toggle source

Syntactic sugar for finding intersections with valid keywords @param values [Array<String>] the collection to use for finding intersecting values

@return [Array<String>] the list of intersecting values

# File lib/reviewer/arguments/keywords.rb, line 125
def intersection_with(values)
  (values & provided).uniq.sort
end
tools() click to toggle source

Provides a collection of enabled Tools for convenient access

@return [Array<Reviewer::Tool>] collection of all currently enabled tools

# File lib/reviewer/arguments/keywords.rb, line 117
def tools
  @tools ||= Reviewer.tools
end