Class: CleoQualityReview::PromptLoader

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

Overview

Loads prompt templates from local or gem-bundled locations

Constant Summary collapse

GEM_PROMPTS_DIRECTORY =
File.expand_path("../../prompts", __dir__)
LOCAL_PROMPTS_DIRECTORY =
".cleo_quality_review"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format:) ⇒ PromptLoader

Returns a new instance of PromptLoader.

Parameters:

  • format (String)

    output format name



21
22
23
# File 'lib/cleo_quality_review/prompt_loader.rb', line 21

def initialize(format:)
  @format = format
end

Class Method Details

.load(format: "human") ⇒ String

Load a prompt template for the given format

Parameters:

  • format (String) (defaults to: "human")

    output format name

Returns:

  • (String)

    prompt template content

Raises:

  • (ArgumentError)

    if no prompt found for the format



15
16
17
# File 'lib/cleo_quality_review/prompt_loader.rb', line 15

def self.load(format: "human")
  new(format: format).load
end

Instance Method Details

#loadString

Load the prompt template

Returns:

  • (String)

    prompt content

Raises:

  • (ArgumentError)

    if no prompt found



29
30
31
32
33
34
35
# File 'lib/cleo_quality_review/prompt_loader.rb', line 29

def load
  prompt_paths.each do |path|
    return File.read(path) if File.file?(path)
  end

  raise ArgumentError, "No prompt found for format #{format.inspect}"
end