Class: Reviewer::Tools
- Inherits:
-
Object
- Object
- Reviewer::Tools
- Includes:
- Enumerable
- Defined in:
- lib/reviewer/tools.rb
Overview
Provides convenient access to subsets of configured tools based on provided arguments, configured tools, their enabled/disabled status, and more.
Instance Method Summary collapse
-
#all ⇒ Array<Tool>
(also: #to_a)
Provides a collection of all configured tools instantiated as Tool instances.
-
#current ⇒ Array<Tool>
Uses the full context of a run to provide the filtered subset of tools to use.
-
#enabled ⇒ Array<Tool>
Provides a collection of all tools that run in the default batch.
-
#failed_from_history ⇒ Array<Tool>
Returns tools that failed in the previous run based on history.
-
#initialize(tags: nil, tool_names: nil, arguments: nil, history: nil, config_file: nil) ⇒ Reviewer::Tools
constructor
Provides an instance to work with for knowing which tools to run in a given context.
-
#specified ⇒ Array<Tool>
Provides a collection of all explicitly-specified-via-command-line tools as Tool instances.
-
#tagged ⇒ Array<Tool>
Provides a collection of all tagged-via-command-line tools as Tool instances.
-
#to_h ⇒ Hash
(also: #inspect)
The current state of all available configured tools regardless of whether they are disabled.
Constructor Details
#initialize(tags: nil, tool_names: nil, arguments: nil, history: nil, config_file: nil) ⇒ Reviewer::Tools
Provides an instance to work with for knowing which tools to run in a given context.
17 18 19 20 21 22 23 |
# File 'lib/reviewer/tools.rb', line 17 def initialize(tags: nil, tool_names: nil, arguments: nil, history: nil, config_file: nil) = @tool_names = tool_names @arguments = arguments @history = history @config_file = config_file end |
Instance Method Details
#all ⇒ Array<Tool> Also known as: to_a
Provides a collection of all configured tools instantiated as Tool instances
34 35 36 |
# File 'lib/reviewer/tools.rb', line 34 def all configured.map { |tool_name, config| Tool.new(tool_name, config: config, history: @history) } end |
#current ⇒ Array<Tool>
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, failed 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.
64 65 66 67 68 |
# File 'lib/reviewer/tools.rb', line 64 def current return enabled unless subset? || failed_keyword? (specified + tagged + failed).uniq end |
#enabled ⇒ Array<Tool>
Provides a collection of all tools that run in the default batch
42 |
# File 'lib/reviewer/tools.rb', line 42 def enabled = @enabled ||= all.reject(&:skip_in_batch?) |
#failed_from_history ⇒ Array<Tool>
Returns tools that failed in the previous run based on history
73 74 75 |
# File 'lib/reviewer/tools.rb', line 73 def failed_from_history all.select { |tool| @history.get(tool.key, :last_status) == :failed } end |
#specified ⇒ Array<Tool>
Provides a collection of all explicitly-specified-via-command-line tools as Tool instances
47 48 49 |
# File 'lib/reviewer/tools.rb', line 47 def specified all.keep_if { |tool| named?(tool) } end |
#tagged ⇒ Array<Tool>
Provides a collection of all tagged-via-command-line tools as Tool instances
54 55 56 |
# File 'lib/reviewer/tools.rb', line 54 def tagged enabled.keep_if { |tool| tagged?(tool) } end |
#to_h ⇒ Hash Also known as: inspect
The current state of all available configured tools regardless of whether they are disabled
28 |
# File 'lib/reviewer/tools.rb', line 28 def to_h = configured |