Class: Reviewer::Tool::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/tool/settings.rb

Overview

Converts/casts tool configuration values and provides appropriate default values if not set.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_key, config:) ⇒ Settings

Creates an instance of settings for retrieving values from the configuration file

Parameters:

  • the unique identifier for the tool in the config file

  • the configuration values to examine for the settings



16
17
18
19
# File 'lib/reviewer/tool/settings.rb', line 16

def initialize(tool_key, config:)
  @tool_key = tool_key.to_sym
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/reviewer/tool/settings.rb', line 7

def config
  @config
end

#tool_keyObject (readonly) Also known as: key

Returns the value of attribute tool_key.



7
8
9
# File 'lib/reviewer/tool/settings.rb', line 7

def tool_key
  @tool_key
end

Instance Method Details

#commandsHash

The collection of configured commands for the tool

Returns:

  • all of the commands configured for the tool



120
# File 'lib/reviewer/tool/settings.rb', line 120

def commands = config.fetch(:commands) { {} }

#descriptionString

The human-readable description of what the tool does

Returns:

  • the configured description or a default placeholder



54
# File 'lib/reviewer/tool/settings.rb', line 54

def description = config.fetch(:description) { "(No description provided for '#{name}')" }

#disabled?Boolean

Returns:



43
# File 'lib/reviewer/tool/settings.rb', line 43

def disabled? = skip_in_batch?

#enabled?Boolean

Returns:



44
# File 'lib/reviewer/tool/settings.rb', line 44

def enabled? = !skip_in_batch?

#envHash

The environment variables to set when running the tool

Returns:

  • configured env vars or empty hash



69
# File 'lib/reviewer/tool/settings.rb', line 69

def env = config.fetch(:env) { {} }

#eql?(other) ⇒ Boolean Also known as: ==

Compares two settings instances for equality based on their configuration

Parameters:

  • the settings to compare against

Returns:

  • true if both have the same configuration



29
30
31
32
# File 'lib/reviewer/tool/settings.rb', line 29

def eql?(other)
  self.class == other.class &&
    state == other.state
end

#files_command(command_type) ⇒ String?

Returns the file-scoped command override for a given command type. When configured, this command replaces the standard command when files are passed.

Parameters:

  • the command type (:review, :format)

Returns:

  • the file-scoped command or nil if not configured



115
# File 'lib/reviewer/tool/settings.rb', line 115

def files_command(command_type) = config.dig(:files, command_type)

#files_flagString

The CLI flag used to pass files to the tool (e.g., '--files')

Returns:

  • the configured flag or empty string if files are passed directly



79
# File 'lib/reviewer/tool/settings.rb', line 79

def files_flag = config.dig(:files, :flag) || ''

#files_patternString?

The glob pattern used to filter which files this tool should process. Patterns without a slash match basenames; patterns with a slash match repository-relative paths and support brace alternatives.

Returns:

  • the pattern (e.g., '.rb' or 'lib,test/**/.rb') or nil



91
# File 'lib/reviewer/tool/settings.rb', line 91

def files_pattern = config.dig(:files, :pattern)

#files_separatorString

The separator used to join multiple file paths in the command

Returns:

  • the configured separator or a space by default



84
# File 'lib/reviewer/tool/settings.rb', line 84

def files_separator = config.dig(:files, :separator) || ' '

#flagsHash

The CLI flags to pass to the tool's review command

Returns:

  • configured flags or empty hash



74
# File 'lib/reviewer/tool/settings.rb', line 74

def flags = config.fetch(:flags) { {} }

#hashInteger

Returns a hash code for comparing settings instances

Returns:

  • hash code based on configuration state



24
# File 'lib/reviewer/tool/settings.rb', line 24

def hash = state.hash

The collection of reference links for the tool (home, install, usage, etc.)

Returns:

  • configured links or empty hash if none



64
# File 'lib/reviewer/tool/settings.rb', line 64

def links = config.fetch(:links) { {} }

#map_to_testsString?

The test framework to use for mapping source files to test files

Returns:

  • the framework name ('minitest' or 'rspec') or nil if not configured



96
# File 'lib/reviewer/tool/settings.rb', line 96

def map_to_tests = config.dig(:files, :map_to_tests)

#max_exit_statusInteger

The largest exit status that can still be considered a success for the command

Returns:

  • the configured max_exit_status for the tool or 0 if one isn't configured



125
# File 'lib/reviewer/tool/settings.rb', line 125

def max_exit_status = commands.fetch(:max_exit_status) { 0 }

#nameString

The human-readable name of the tool

Returns:

  • the configured name or capitalized tool key



49
# File 'lib/reviewer/tool/settings.rb', line 49

def name = config.fetch(:name) { tool_key.to_s.capitalize }

#skip_in_batch?Boolean

Returns:



35
36
37
38
39
40
41
# File 'lib/reviewer/tool/settings.rb', line 35

def skip_in_batch?
  if config.key?(:skip_in_batch)
    config.fetch(:skip_in_batch) { false }
  else
    config.fetch(:disabled) { false }
  end
end

#summary_labelString?

The label template for displaying the extracted summary detail

Returns:

  • the configured label or nil



108
# File 'lib/reviewer/tool/settings.rb', line 108

def summary_label = config.dig(:summary, :label)

#summary_patternString?

The regex pattern for extracting a summary detail from tool output

Returns:

  • the configured pattern or nil



103
# File 'lib/reviewer/tool/settings.rb', line 103

def summary_pattern = config.dig(:summary, :pattern)

#supports_files?Boolean

Returns:



98
# File 'lib/reviewer/tool/settings.rb', line 98

def supports_files? = config.key?(:files)

#tagsArray<String>

The tags used to categorize and filter the tool

Returns:

  • configured tags or empty array



59
# File 'lib/reviewer/tool/settings.rb', line 59

def tags = config.fetch(:tags) { [] }