Class: AIRefactor::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/ai_refactor/context.rb

Instance Method Summary collapse

Constructor Details

#initialize(files:, text:, logger:) ⇒ Context

Returns a new instance of Context.



5
6
7
8
9
# File 'lib/ai_refactor/context.rb', line 5

def initialize(files:, text:, logger:)
  @files = files
  @text = text
  @logger = logger
end

Instance Method Details

#prepare_contextObject



11
12
13
14
15
16
17
18
19
# File 'lib/ai_refactor/context.rb', line 11

def prepare_context
  context = read_contexts&.compact
  file_context = (context && context.size.positive?) ? "Here is some related files:\n\n#{context.join("\n")}" : ""
  if @text.nil? || @text.empty?
    file_context
  else
    "\n#{file_context}\n\n#{@text}\n"
  end
end