Class: Ace::Retro::Molecules::RetroLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/retro/molecules/retro_loader.rb

Overview

Loads a retro from its directory, parsing frontmatter + body, and enumerating folder contents (reports, action-item files).

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_scan_result(scan_result) ⇒ Retro?

Load a retro from a ScanResult

Parameters:

  • scan_result (ScanResult)

    Scan result pointing to the retro directory

Returns:

  • (Retro, nil)

    Loaded retro or nil if load fails



21
22
23
24
25
# File 'lib/ace/retro/molecules/retro_loader.rb', line 21

def self.from_scan_result(scan_result)
  new.load(scan_result.dir_path,
    id: scan_result.id,
    special_folder: scan_result.special_folder)
end

Instance Method Details

#load(dir_path, id: nil, special_folder: nil) ⇒ Retro?

Load a retro from a directory path

Parameters:

  • dir_path (String)

    Path to the retro directory

  • id (String, nil) (defaults to: nil)

    Known ID (extracted from folder name if nil)

  • special_folder (String, nil) (defaults to: nil)

    Known special folder

Returns:

  • (Retro, nil)

    Loaded retro or nil



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ace/retro/molecules/retro_loader.rb', line 32

def load(dir_path, id: nil, special_folder: nil)
  return nil unless Dir.exist?(dir_path)

  # Find the retro file
  retro_file = Dir.glob(File.join(dir_path, Atoms::RetroFilePattern::FILE_GLOB)).first
  return nil unless retro_file

  # Extract ID from folder name if not provided
  folder_name = File.basename(dir_path)
  id ||= extract_id(folder_name)

  # Parse the retro file
  content = File.read(retro_file)
  frontmatter, body = Ace::Support::Items::Atoms::FrontmatterParser.parse(content)

  # Enumerate folder contents (all non-.retro.md files in the directory)
  folder_contents = list_folder_contents(dir_path)

  # Extract title from frontmatter or body header
  title = frontmatter["title"] || Ace::Support::Items::Atoms::TitleExtractor.extract(body) || folder_name

  # Parse creation time
  created_at = parse_created_at(frontmatter["created_at"], id)

  # Extract known fields, preserve others in metadata
  known_keys = %w[id status title type tags created_at]
   = frontmatter.reject { |k, _| known_keys.include?(k) }

  Models::Retro.new(
    id: id || frontmatter["id"],
    status: frontmatter["status"] || "active",
    title: title,
    type: frontmatter["type"] || "standard",
    tags: Array(frontmatter["tags"]),
    content: body.to_s.strip,
    path: dir_path,
    file_path: retro_file,
    special_folder: special_folder,
    created_at: created_at,
    folder_contents: folder_contents,
    metadata: 
  )
rescue
  nil
end