Class: Reviewer::Setup::Detector

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/setup/detector.rb

Overview

Scans a project directory to detect which review tools are applicable based on Gemfile.lock contents, config files, and directory structure.

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_dir = Pathname.pwd) ⇒ Detector

Creates a detector for scanning a project directory for supported tools

Parameters:

  • project_dir (Pathname, String) (defaults to: Pathname.pwd)

    the project root to scan



26
27
28
# File 'lib/reviewer/setup/detector.rb', line 26

def initialize(project_dir = Pathname.pwd)
  @project_dir = Pathname(project_dir)
end

Instance Attribute Details

#project_dirObject (readonly)

Returns the value of attribute project_dir.



20
21
22
# File 'lib/reviewer/setup/detector.rb', line 20

def project_dir
  @project_dir
end

Instance Method Details

#detectArray<Result>

Scans the project and returns detection results for matching tools

Returns:

  • (Array<Result>)

    detected tools with evidence



33
34
35
36
37
38
39
40
# File 'lib/reviewer/setup/detector.rb', line 33

def detect
  gems = GemfileLock.new(project_dir.join('Gemfile.lock')).gem_names

  Catalog.all.filter_map do |key, definition|
    reasons = reasons_for(definition[:detect], gems)
    Result.new(key: key, reasons: reasons) if reasons.any?
  end
end