Class: Ace::Support::Items::Molecules::DocumentLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/items/molecules/document_loader.rb

Overview

Loads a document from an item directory: finds the spec file, parses frontmatter/body, extracts title, and enumerates attachments.

Class Method Summary collapse

Class Method Details

.from_scan_result(scan_result, spec_extension:, file_pattern: nil) ⇒ LoadedDocument?

Load a document from a ScanResult

Parameters:

  • scan_result (ScanResult)

    Scan result with dir_path and file_path

  • file_pattern (String) (defaults to: nil)

    Glob pattern (unused when file_path present, kept for API consistency)

  • spec_extension (String)

    Extension to exclude from attachments

Returns:

  • (LoadedDocument, nil)

    Loaded document or nil



33
34
35
36
37
38
39
40
# File 'lib/ace/support/items/molecules/document_loader.rb', line 33

def self.from_scan_result(scan_result, spec_extension:, file_pattern: nil)
  return nil unless scan_result&.dir_path && Dir.exist?(scan_result.dir_path)

  spec_file = scan_result.file_path || Dir.glob(File.join(scan_result.dir_path, file_pattern)).first
  return nil unless spec_file

  build_document(scan_result.dir_path, spec_file, spec_extension)
end

.load(dir_path, file_pattern:, spec_extension:) ⇒ LoadedDocument?

Load a document from a directory path

Parameters:

  • dir_path (String)

    Path to item directory

  • file_pattern (String)

    Glob pattern for spec files (e.g., “*.idea.s.md”)

  • spec_extension (String)

    Extension to exclude from attachments (e.g., “.idea.s.md”)

Returns:

  • (LoadedDocument, nil)

    Loaded document or nil if not found



19
20
21
22
23
24
25
26
# File 'lib/ace/support/items/molecules/document_loader.rb', line 19

def self.load(dir_path, file_pattern:, spec_extension:)
  return nil unless Dir.exist?(dir_path)

  spec_file = Dir.glob(File.join(dir_path, file_pattern)).first
  return nil unless spec_file

  build_document(dir_path, spec_file, spec_extension)
end