Class: Ask::RAG::Loader::Directory
- Defined in:
- lib/ask/rag/loader/directory.rb
Overview
Walks a directory tree and loads all supported file types.
Automatically detects file types by extension and dispatches to the appropriate loader. Ignores common non-source directories and files.
Constant Summary collapse
- EXTENSION_MAP =
{ ".txt" => :text, ".md" => :markdown, ".markdown" => :markdown, ".html" => :html, ".htm" => :html, ".csv" => :csv, ".json" => :json, ".pdf" => :pdf }.freeze
- SKIP_DIRS =
Directories to skip when walking (matches basename).
%w[ .git .svn .hg .bzr _darcs node_modules .bundle vendor .yardoc coverage tmp log public/assets ].freeze
Instance Method Summary collapse
-
#initialize(pattern: nil, skip_dirs: SKIP_DIRS) ⇒ Directory
constructor
A new instance of Directory.
-
#load(path) ⇒ Array<Ask::Document>
Load all supported files from a directory tree.
Methods inherited from Base
Constructor Details
Instance Method Details
#load(path) ⇒ Array<Ask::Document>
Load all supported files from a directory tree.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ask/rag/loader/directory.rb', line 51 def load(path) docs = [] files(path).each do |file| loader = loader_for(file) next unless loader docs.concat(loader.load(file)) rescue StandardError => e warn "[ask-rag] Skipping #{file}: #{e.class}: #{e.}" end docs end |