lib/reviewer/arguments/keywords.rb in reviewer-0.1.3 vs lib/reviewer/arguments/keywords.rb in reviewer-0.1.4

- old
+ new

@@ -1,9 +1,7 @@ # frozen_string_literal: true -require_relative 'keywords/git' - module Reviewer class Arguments # Handles interpreting all 'leftover' arguments and translating them to file-related, # tag-related, or tool-related arguments class Keywords @@ -11,32 +9,48 @@ attr_accessor :provided alias raw provided + # 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] def initialize(*provided) @provided = Array(provided.flatten) end + # 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 def to_a provided end + # 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 def to_s to_a.join(',') end - def inspect + # 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 + def to_h { provided: provided, recognized: recognized, unrecognized: unrecognized, reserved: reserved, for_tags: for_tags, for_tool_names: for_tool_names } end + alias inspect to_h # Extracts reserved keywords from the provided arguments # # @return [Array<String>] intersection of provided arguments and reserved keywords def reserved @@ -80,37 +94,37 @@ # Provides the complete list of all configured tags for enabled tools # # @return [Array<String>] all unique configured tags def configured_tags - enabled_tools.map(&:tags).flatten.uniq.sort + tools.enabled.map(&:tags).flatten.uniq.sort end # Provides the complete list of all configured tool names for enabled tools # - # @return [Array<String>] all unique configured and enabled tools + # @return [Array<String>] all unique configured tools 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 - enabled_tools.map { |tool| tool.key.to_s }.flatten.uniq + tools.all.map { |tool| tool.key.to_s } end private # Provides a collection of enabled Tools for convenient access # # @return [Array<Reviewer::Tool>] collection of all currently enabled tools - def enabled_tools - @enabled_tools ||= Reviewer.tools.enabled + def tools + @tools ||= Reviewer.tools end # 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 def intersection_with(values) - values.intersection(provided).uniq.sort + (values & provided).uniq.sort end end end end