Class: RubyAiGemContext::FileCollector

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

Overview

Collects and reads files from the project for context generation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path = Dir.pwd, folders: nil) ⇒ FileCollector

Returns a new instance of FileCollector.

Parameters:

  • root_path (String) (defaults to: Dir.pwd) —

    Project root directory

  • folders (Array<String>, String, nil) (defaults to: nil) —

    Specific folders to scan, or nil for whole project



10
11
12
13
# File 'lib/ruby_ai_gem_context/file_collector.rb', line 10

def initialize(root_path = Dir.pwd, folders: nil)
  @root_path = root_path
  @folders = normalize_folders(folders)
end

Instance Attribute Details

#folders ⇒ Object (readonly)

Returns the value of attribute folders.



6
7
8
# File 'lib/ruby_ai_gem_context/file_collector.rb', line 6

def folders
  @folders
end

#root_path ⇒ Object (readonly)

Returns the value of attribute root_path.



6
7
8
# File 'lib/ruby_ai_gem_context/file_collector.rb', line 6

def root_path
  @root_path
end

Instance Method Details

#collect ⇒ Hash

Collect all relevant files based on configuration

Returns:

  • (Hash) —

    Hash with file paths as keys and contents as values



17
18
19
20
21
22
23
24
25
# File 'lib/ruby_ai_gem_context/file_collector.rb', line 17

def collect
  files = {}

  scan_paths.each do |scan_path|
    collect_from_path(scan_path, files)
  end

  files
end

#summary ⇒ Hash

Get a summary of what will be collected

Returns:

  • (Hash) —

    Stats about files to be collected



29
30
31
32
33
34
35
36
# File 'lib/ruby_ai_gem_context/file_collector.rb', line 29

def summary
  files = collect
  {
    total_files: files.size,
    total_size: files.values.sum(&:bytesize),
    by_extension: count_by_extension(files)
  }
end