Class: Ace::Retro::Molecules::RetroCreator

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

Overview

Creates new retros with b36ts IDs, folder+file creation. Supports –type and –move-to options.

Instance Method Summary collapse

Constructor Details

#initialize(root_dir:, config: {}) ⇒ RetroCreator

Returns a new instance of RetroCreator.

Parameters:

  • root_dir (String)

    Root directory for retros

  • config (Hash) (defaults to: {})

    Configuration hash



18
19
20
21
# File 'lib/ace/retro/molecules/retro_creator.rb', line 18

def initialize(root_dir:, config: {})
  @root_dir = root_dir
  @config = config
end

Instance Method Details

#create(title, type: nil, tags: [], move_to: nil, time: Time.now.utc) ⇒ Retro

Create a new retro

Parameters:

  • title (String)

    Retro title

  • type (String) (defaults to: nil)

    Retro type (standard, conversation-analysis, self-review)

  • tags (Array<String>) (defaults to: [])

    Tags for the retro

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

    Target folder for the retro

  • time (Time) (defaults to: Time.now.utc)

    Creation time (default: now)

Returns:

  • (Retro)

    Created retro object

Raises:

  • (ArgumentError)


30
31
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
# File 'lib/ace/retro/molecules/retro_creator.rb', line 30

def create(title, type: nil, tags: [], move_to: nil, time: Time.now.utc)
  raise ArgumentError, "Title is required" if title.nil? || title.strip.empty?

  effective_type = type || @config.dig("retro", "default_type") || "standard"

  # Generate ID and slugs
  id = Atoms::RetroIdFormatter.generate(time)
  folder_slug = generate_folder_slug(title)
  file_slug = generate_file_slug(title)

  # Determine target directory
  target_dir = determine_target_dir(move_to)
  FileUtils.mkdir_p(target_dir)

  # Create retro folder (ensure unique name if ID collision occurs)
  folder_name, _ = unique_folder_name(id, folder_slug, target_dir)
  retro_dir = File.join(target_dir, folder_name)
  FileUtils.mkdir_p(retro_dir)

  # Build frontmatter
  frontmatter = Atoms::RetroFrontmatterDefaults.build(
    id: id,
    title: title,
    type: effective_type,
    tags: tags,
    status: "active",
    created_at: time
  )

  # Write retro file
  file_content = build_file_content(frontmatter, title, effective_type)
  retro_filename = Atoms::RetroFilePattern.retro_filename(id, file_slug)
  retro_file = File.join(retro_dir, retro_filename)
  File.write(retro_file, file_content)

  # Load and return the created retro
  loader = RetroLoader.new
  special_folder = Ace::Support::Items::Atoms::SpecialFolderDetector.detect_in_path(
    retro_dir, root: @root_dir
  )
  loader.load(retro_dir, id: id, special_folder: special_folder)
end