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].freeze
Instance Attribute Summary collapse
-
#provided ⇒ Array<String>
(also: #raw)
The keywords extracted from the command-line arguments.
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.
-
#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) ⇒ 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
Proves 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) ⇒ self
Generates an instance of parsed keywords from the provided arguments
21 22 23 |
# File 'lib/reviewer/arguments/keywords.rb', line 21 def initialize(*provided) @provided = Array(provided.flatten) 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 125 126 127 128 129 130 131 |
# File 'lib/reviewer/arguments/keywords.rb', line 10 class Keywords RESERVED = %w[staged].freeze attr_accessor :provided 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 # # @return [self] 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 # 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 # Extracts reserved keywords from the provided arguments # # @return [Array<String>] intersection of provided arguments and reserved keywords def reserved intersection_with RESERVED end # Extracts keywords that match configured tags for enabled tools # # @return [Array<String>] intersection of provided arguments and configured tags for tools def intersection_with end # 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 end # Extracts keywords that match any possible recognized keyword values # # @return [Array<String>] intersection of provided arguments and recognizable keywords def recognized intersection_with possible end # 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 end # Provides the complete list of all recognized keywords based on configuration # # @return [Array<String>] all keywords that Reviewer can recognized def possible (RESERVED + + configured_tool_names).uniq.sort end # Provides the complete list of all configured tags for enabled tools # # @return [Array<String>] all unique configured tags def 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 # 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 # Provides a collection of enabled Tools for convenient access # # @return [Array<Reviewer::Tool>] collection of all currently enabled tools 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 & provided).uniq.sort end end |
Instance Method Details
#configured_tags ⇒ Array<String>
Provides the complete list of all configured tags for enabled tools
101 102 103 |
# File 'lib/reviewer/arguments/keywords.rb', line 101 def 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
108 109 110 111 112 113 |
# File 'lib/reviewer/arguments/keywords.rb', line 108 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 ⇒ Array<String>
Extracts keywords that match configured tags for enabled tools
66 67 68 |
# File 'lib/reviewer/arguments/keywords.rb', line 66 def intersection_with end |
#for_tool_names ⇒ Array<String>
Extracts keywords that match configured tool keys
73 74 75 |
# File 'lib/reviewer/arguments/keywords.rb', line 73 def for_tool_names intersection_with configured_tool_names end |
#possible ⇒ Array<String>
Provides the complete list of all recognized keywords based on configuration
94 95 96 |
# File 'lib/reviewer/arguments/keywords.rb', line 94 def possible (RESERVED + + configured_tool_names).uniq.sort end |
#recognized ⇒ Array<String>
Extracts keywords that match any possible recognized keyword values
80 81 82 |
# File 'lib/reviewer/arguments/keywords.rb', line 80 def recognized intersection_with possible end |
#reserved ⇒ Array<String>
Extracts reserved keywords from the provided arguments
59 60 61 |
# File 'lib/reviewer/arguments/keywords.rb', line 59 def reserved intersection_with RESERVED end |
#to_a ⇒ Array
Proves the full list of raw keyword arguments explicitly passed via command-line as an array
28 29 30 |
# File 'lib/reviewer/arguments/keywords.rb', line 28 def to_a provided end |
#to_h ⇒ Hash Also known as: inspect
Summary of the state of keyword arguments based on how Reviewer parsed them
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/reviewer/arguments/keywords.rb', line 44 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
36 37 38 |
# File 'lib/reviewer/arguments/keywords.rb', line 36 def to_s to_a.join(',') end |
#unrecognized ⇒ Array<String>
Extracts keywords that don’t match any possible recognized keyword values
87 88 89 |
# File 'lib/reviewer/arguments/keywords.rb', line 87 def unrecognized (provided - recognized).uniq.sort end |