Class: Reviewer::Arguments::Keywords
- Inherits:
-
Object
- Object
- Reviewer::Arguments::Keywords
- Defined in:
- lib/reviewer/arguments/keywords.rb
Overview
Handles interpreting all ‘leftover’ arguments and translating them to file-related, tag-related, or tool-related arguments
Constant Summary collapse
- RESERVED =
%w[staged unstaged modified untracked failed].freeze
Instance Attribute Summary collapse
-
#provided ⇒ Array<String>
(also: #raw)
The keywords extracted from the command-line arguments.
-
#tools ⇒ Tools
writeonly
Sets the tools collection after initialization when tools become available.
Instance Method Summary collapse
-
#configured_tags ⇒ Array<String>
Provides the complete list of all configured tags for enabled tools.
-
#configured_tool_names ⇒ Array<String>
Provides the complete list of all configured tool names for enabled tools.
-
#failed? ⇒ Boolean
Whether the
failedkeyword was provided. -
#for_tags ⇒ Array<String>
Extracts keywords that match configured tags for enabled tools.
-
#for_tool_names ⇒ Array<String>
Extracts keywords that match configured tool keys.
-
#initialize(*provided, tools: nil) ⇒ self
constructor
Generates an instance of parsed keywords from the provided arguments.
-
#possible ⇒ Array<String>
Provides the complete list of all recognized keywords based on configuration.
-
#recognized ⇒ Array<String>
Extracts keywords that match any possible recognized keyword values.
-
#reserved ⇒ Array<String>
Extracts reserved keywords from the provided arguments.
-
#to_a ⇒ Array<String>
Provides the full list of raw keyword arguments explicitly passed via command-line as an array.
-
#to_h ⇒ Hash
(also: #inspect)
Summary of the state of keyword arguments based on how Reviewer parsed them.
-
#to_s ⇒ String
Provides the full list of raw keyword arguments explicitly passed via command-line as a comma-separated string.
-
#unrecognized ⇒ Array<String>
Extracts keywords that don’t match any possible recognized keyword values.
Constructor Details
#initialize(*provided, tools: nil) ⇒ self
Generates an instance of parsed keywords from the provided arguments
27 28 29 30 |
# File 'lib/reviewer/arguments/keywords.rb', line 27 def initialize(*provided, tools: nil) @provided = Array(provided.flatten) @tools = tools end |
Instance Attribute Details
#provided ⇒ Array<String> Also known as: raw
Returns the keywords extracted from the command-line arguments.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/reviewer/arguments/keywords.rb', line 10 class Keywords RESERVED = %w[staged unstaged modified untracked failed].freeze attr_reader :provided # Sets the tools collection after initialization when tools become available # @param value [Tools] the configured tools collection # @return [Tools] the tools collection attr_writer :tools alias raw provided # Generates an instance of parsed keywords from the provided arguments # @param provided [Array<String>] the leftover (non-flag) arguments from the command line # @param tools [Tools] the collection of configured tools for keyword recognition # # @return [self] def initialize(*provided, tools: nil) @provided = Array(provided.flatten) @tools = tools end # Provides the full list of raw keyword arguments explicitly passed via command-line as an array # # @return [Array<String>] full collection of the provided keyword arguments def to_a = provided # 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 keyword arguments as a string def to_s = to_a.join(',') # 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_tool_names: for_tool_names } end alias inspect to_h # Whether the `failed` keyword was provided # # @return [Boolean] true if the `failed` keyword is present def failed? = provided.include?('failed') # Extracts reserved keywords from the provided arguments # # @return [Array<String>] intersection of provided arguments and reserved keywords def reserved = intersection_with(RESERVED) # Extracts keywords that match configured tags for enabled tools # # @return [Array<String>] intersection of provided arguments and configured tags for tools def = intersection_with() # Extracts keywords that match configured tool keys # # @return [Array<String>] intersection of provided arguments and configured tool names def for_tool_names = intersection_with(configured_tool_names) # Extracts keywords that match any possible recognized keyword values # # @return [Array<String>] intersection of provided arguments and recognizable keywords def recognized = intersection_with(possible) # Extracts keywords that don't match any possible recognized keyword values # # @return [Array<String>] leftover keywords that weren't recognized def unrecognized = (provided - recognized).uniq.sort # Provides the complete list of all recognized keywords based on configuration # # @return [Array<String>] all keywords that Reviewer can recognize def possible = (RESERVED + + configured_tool_names).uniq.sort # Provides the complete list of all configured tags for enabled tools # # @return [Array<String>] all unique configured tags def return [] unless tools 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 tools def configured_tool_names return [] unless tools # 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 private attr_reader :tools # 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 & provided).uniq.sort end |
#tools=(value) ⇒ Tools
Sets the tools collection after initialization when tools become available
18 19 20 |
# File 'lib/reviewer/arguments/keywords.rb', line 18 def tools=(value) @tools = value end |
Instance Method Details
#configured_tags ⇒ Array<String>
Provides the complete list of all configured tags for enabled tools
97 98 99 100 101 |
# File 'lib/reviewer/arguments/keywords.rb', line 97 def return [] unless tools tools.enabled.map(&:tags).flatten.uniq.sort end |
#configured_tool_names ⇒ Array<String>
Provides the complete list of all configured tool names for enabled tools
106 107 108 109 110 111 112 113 |
# File 'lib/reviewer/arguments/keywords.rb', line 106 def configured_tool_names return [] unless tools # 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 |
#failed? ⇒ Boolean
Whether the failed keyword was provided
62 |
# File 'lib/reviewer/arguments/keywords.rb', line 62 def failed? = provided.include?('failed') |
#for_tags ⇒ Array<String>
Extracts keywords that match configured tags for enabled tools
72 |
# File 'lib/reviewer/arguments/keywords.rb', line 72 def = intersection_with() |
#for_tool_names ⇒ Array<String>
Extracts keywords that match configured tool keys
77 |
# File 'lib/reviewer/arguments/keywords.rb', line 77 def for_tool_names = intersection_with(configured_tool_names) |
#possible ⇒ Array<String>
Provides the complete list of all recognized keywords based on configuration
92 |
# File 'lib/reviewer/arguments/keywords.rb', line 92 def possible = (RESERVED + + configured_tool_names).uniq.sort |
#recognized ⇒ Array<String>
Extracts keywords that match any possible recognized keyword values
82 |
# File 'lib/reviewer/arguments/keywords.rb', line 82 def recognized = intersection_with(possible) |
#reserved ⇒ Array<String>
Extracts reserved keywords from the provided arguments
67 |
# File 'lib/reviewer/arguments/keywords.rb', line 67 def reserved = intersection_with(RESERVED) |
#to_a ⇒ Array<String>
Provides the full list of raw keyword arguments explicitly passed via command-line as an array
35 |
# File 'lib/reviewer/arguments/keywords.rb', line 35 def to_a = provided |
#to_h ⇒ Hash Also known as: inspect
Summary of the state of keyword arguments based on how Reviewer parsed them
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/reviewer/arguments/keywords.rb', line 47 def to_h { provided: provided, recognized: recognized, unrecognized: unrecognized, reserved: reserved, for_tags: , for_tool_names: for_tool_names } end |
#to_s ⇒ String
Provides the full list of raw keyword arguments explicitly passed via command-line as a
comma-separated string
41 |
# File 'lib/reviewer/arguments/keywords.rb', line 41 def to_s = to_a.join(',') |
#unrecognized ⇒ Array<String>
Extracts keywords that don’t match any possible recognized keyword values
87 |
# File 'lib/reviewer/arguments/keywords.rb', line 87 def unrecognized = (provided - recognized).uniq.sort |