Class: Appydave::Tools::GptContext::FileCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/appydave/tools/gpt_context/file_collector.rb

Overview

Gathers file names and content based on include and exclude patterns

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ FileCollector

Returns a new instance of FileCollector.



9
10
11
12
13
14
15
16
17
# File 'lib/appydave/tools/gpt_context/file_collector.rb', line 9

def initialize(options)
  @options = options
  @include_patterns = options.include_patterns
  @exclude_patterns = options.exclude_patterns
  @format = options.format
  @working_directory = File.expand_path(options.working_directory)
  puts @working_directory
  @line_limit = options.line_limit
end

Instance Method Details

#buildObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/appydave/tools/gpt_context/file_collector.rb', line 19

def build
  FileUtils.cd(@working_directory) if @working_directory && Dir.exist?(@working_directory)

  formats = @format.split(',')
  result = formats.map do |fmt|
    case fmt
    when 'tree'
      build_tree
    when 'content'
      build_content
    when 'json'
      build_json
    else
      ''
    end
  end.join("\n\n")

  FileUtils.cd(Dir.home) if @working_directory

  result
end