Class: RubyAiGemContext::Generator

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

Overview

Generates context files using RubyLLM

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform:, file_collector:, **options) ⇒ Generator

Returns a new instance of Generator.

Parameters:

  • platform (Class) —

    Platform class (e.g., Platforms::Claude)

  • file_collector (FileCollector) —

    Collector with project files

  • options (Hash) —

    Additional options



13
14
15
16
17
# File 'lib/ruby_ai_gem_context/generator.rb', line 13

def initialize(platform:, file_collector:, **options)
  @platform = platform
  @file_collector = file_collector
  @options = options
end

Instance Attribute Details

#file_collector ⇒ Object (readonly)

Returns the value of attribute file_collector.



8
9
10
# File 'lib/ruby_ai_gem_context/generator.rb', line 8

def file_collector
  @file_collector
end

#options ⇒ Object (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/ruby_ai_gem_context/generator.rb', line 8

def options
  @options
end

#platform ⇒ Object (readonly)

Returns the value of attribute platform.



8
9
10
# File 'lib/ruby_ai_gem_context/generator.rb', line 8

def platform
  @platform
end

Instance Method Details

#build_prompt(files) ⇒ Object

Build the full prompt including project context



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_ai_gem_context/generator.rb', line 30

def build_prompt(files)
  <<~PROMPT
    #{platform.generation_prompt}

    ---

    Here is the project's source code and files for context:

    #{format_files(files)}
  PROMPT
end

#generate ⇒ String

Generate content for the platform

Returns:

  • (String) —

    Generated content



21
22
23
24
25
26
27
# File 'lib/ruby_ai_gem_context/generator.rb', line 21

def generate
  files = file_collector.collect
  prompt = build_prompt(files)

  response = chat(prompt)
  response.content
end