Class: Reviewer::Setup::Generator

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

Overview

Produces .reviewer.yml YAML content from a list of detected tool keys. Orchestrates which tools to include; delegates per-tool rendering to ToolBlock.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_keys, project_dir: Pathname.pwd) ⇒ Generator

Creates a generator for producing .reviewer.yml configuration

Parameters:

  • tool_keys (Array<Symbol>)

    catalog tool keys to include in config

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

    the project root (used for package manager detection)



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

def initialize(tool_keys, project_dir: Pathname.pwd)
  @tool_keys = tool_keys
  @project_dir = Pathname(project_dir)
end

Instance Attribute Details

#project_dirObject (readonly)

Returns the value of attribute project_dir.



12
13
14
# File 'lib/reviewer/setup/generator.rb', line 12

def project_dir
  @project_dir
end

#tool_keysObject (readonly)

Returns the value of attribute tool_keys.



12
13
14
# File 'lib/reviewer/setup/generator.rb', line 12

def tool_keys
  @tool_keys
end

Instance Method Details

#generateString

Generates YAML configuration string for the detected tools

Returns:

  • (String)

    valid YAML for .reviewer.yml



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/reviewer/setup/generator.rb', line 27

def generate
  return "--- {}\n" if tool_keys.empty?

  blocks = tool_keys.filter_map do |key|
    definition = Catalog.config_for(key)
    next unless definition

    ToolBlock.new(key, definition, js_runner: js_runner).to_s
  end

  "---\n#{blocks.join("\n")}"
end