Class: CleoQualityReview::Checks::QualityCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/cleo_quality_review/checks/quality_check.rb

Overview

Base class for quality check implementations

Direct Known Subclasses

Debride, Fasterer, Flog, Reek

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_runner:, timestamp:) ⇒ QualityCheck

Returns a new instance of QualityCheck.

Parameters:

  • command_runner (CommandRunner)

    for executing shell commands

  • timestamp (Integer)

    epoch milliseconds for the run



52
53
54
55
# File 'lib/cleo_quality_review/checks/quality_check.rb', line 52

def initialize(command_runner:, timestamp:)
  @command_runner = command_runner
  @timestamp = timestamp
end

Class Attribute Details

.check_nameString

Returns identifier for this check.

Returns:

  • (String)

    identifier for this check



16
17
18
# File 'lib/cleo_quality_review/checks/quality_check.rb', line 16

def check_name
  @check_name
end

.output_extensionString

Returns file extension for raw output.

Returns:

  • (String)

    file extension for raw output



28
29
30
# File 'lib/cleo_quality_review/checks/quality_check.rb', line 28

def output_extension
  @output_extension
end

.tool_nameString

Returns tool name for result attribution.

Returns:

  • (String)

    tool name for result attribution



20
21
22
# File 'lib/cleo_quality_review/checks/quality_check.rb', line 20

def tool_name
  @tool_name
end

.tool_typeString

Returns category for this tool’s findings.

Returns:

  • (String)

    category for this tool’s findings



24
25
26
# File 'lib/cleo_quality_review/checks/quality_check.rb', line 24

def tool_type
  @tool_type
end

Class Method Details

.inherited(subclass) ⇒ void

This method returns an undefined value.

Set default output extension for subclasses

Parameters:

  • subclass (Class)

    the inheriting class



34
35
36
37
# File 'lib/cleo_quality_review/checks/quality_check.rb', line 34

def inherited(subclass)
  super
  subclass.output_extension = "txt"
end

.output_metadataObject



39
40
41
42
43
44
45
46
# File 'lib/cleo_quality_review/checks/quality_check.rb', line 39

def 
  {
    check_name: check_name,
    tool_name: tool_name,
    tool_type: tool_type,
    extension: output_extension,
  }
end

Instance Method Details

#run(files) ⇒ CheckOutput

Run the quality check on the given files

Parameters:

  • files (Array<String>)

    file paths to analyze

Returns:



61
62
63
64
65
66
67
68
69
# File 'lib/cleo_quality_review/checks/quality_check.rb', line 61

def run(files)
  return empty_output if files.empty?

  command_result = command_runner.run(*command(files))
  build_output(
    raw_output: raw_output(command_result),
    results: parse(command_result.stdout, parseable_stderr(command_result)),
  )
end