Class: Ace::Retro::Organisms::RetroManager

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/retro/organisms/retro_manager.rb

Overview

Orchestrates all retro CRUD operations. Entry point for retro management with config-driven root directory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_dir: nil, config: nil) ⇒ RetroManager

Returns a new instance of RetroManager.

Parameters:

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

    Override root directory for retros

  • config (Hash, nil) (defaults to: nil)

    Override configuration



22
23
24
25
# File 'lib/ace/retro/organisms/retro_manager.rb', line 22

def initialize(root_dir: nil, config: nil)
  @config = config || load_config
  @root_dir = root_dir || resolve_root_dir
end

Instance Attribute Details

#last_folder_countsObject (readonly)

Returns the value of attribute last_folder_counts.



18
19
20
# File 'lib/ace/retro/organisms/retro_manager.rb', line 18

def last_folder_counts
  @last_folder_counts
end

#last_list_totalObject (readonly)

Returns the value of attribute last_list_total.



18
19
20
# File 'lib/ace/retro/organisms/retro_manager.rb', line 18

def last_list_total
  @last_list_total
end

#root_dirString (readonly)

Get the root directory

Returns:

  • (String)

    Absolute path to retros root



121
122
123
# File 'lib/ace/retro/organisms/retro_manager.rb', line 121

def root_dir
  @root_dir
end

Instance Method Details

#create(title, type: nil, tags: [], move_to: nil) ⇒ Retro

Create a new retro

Parameters:

  • title (String)

    Retro title

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

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

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

    Tags

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

    Target folder

Returns:

  • (Retro)

    Created retro



33
34
35
36
37
# File 'lib/ace/retro/organisms/retro_manager.rb', line 33

def create(title, type: nil, tags: [], move_to: nil)
  ensure_root_dir
  creator = Molecules::RetroCreator.new(root_dir: @root_dir, config: @config)
  creator.create(title, type: type, tags: tags, move_to: move_to)
end

#list(status: nil, type: nil, in_folder: "next", tags: []) ⇒ Array<Retro>

List retros with optional filtering

Parameters:

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

    Filter by status

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

    Filter by type

  • in_folder (String, nil) (defaults to: "next")

    Filter by special folder (default: “next” = root items only)

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

    Filter by tags (any match)

Returns:

  • (Array<Retro>)

    List of retros



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ace/retro/organisms/retro_manager.rb', line 59

def list(status: nil, type: nil, in_folder: "next", tags: [])
  scanner = Molecules::RetroScanner.new(@root_dir)
  scan_results = scanner.scan_in_folder(in_folder)
  @last_list_total = scanner.last_scan_total
  @last_folder_counts = scanner.last_folder_counts

  loader = Molecules::RetroLoader.new
  retros = scan_results.filter_map do |sr|
    loader.load(sr.dir_path, id: sr.id, special_folder: sr.special_folder)
  end

  retros = retros.select { |r| r.status == status } if status
  retros = retros.select { |r| r.type == type } if type
  retros = filter_by_tags(retros, tags) if tags.any?

  retros
end

#show(ref) ⇒ Retro?

Show (load) a single retro by reference

Parameters:

  • ref (String)

    Full ID (6 chars) or suffix shortcut (3 chars)

Returns:

  • (Retro, nil)

    Loaded retro or nil if not found



42
43
44
45
46
47
48
49
50
51
# File 'lib/ace/retro/organisms/retro_manager.rb', line 42

def show(ref)
  resolver = Molecules::RetroResolver.new(@root_dir)
  scan_result = resolver.resolve(ref)
  return nil unless scan_result

  loader = Molecules::RetroLoader.new
  loader.load(scan_result.dir_path,
    id: scan_result.id,
    special_folder: scan_result.special_folder)
end

#update(ref, set: {}, add: {}, remove: {}, move_to: nil) ⇒ Retro?

Update a retro’s fields and optionally move to a folder.

Parameters:

  • ref (String)

    Retro reference

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

    Fields to set (key => value)

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

    Fields to add to (for arrays like tags)

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

    Fields to remove from (for arrays)

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

    Target folder to move to (archive, maybe, next/root//)

Returns:

  • (Retro, nil)

    Updated retro or nil if not found



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ace/retro/organisms/retro_manager.rb', line 84

def update(ref, set: {}, add: {}, remove: {}, move_to: nil)
  scan_result = resolve_scan_result(ref)
  return nil unless scan_result

  loader = Molecules::RetroLoader.new
  retro = loader.load(scan_result.dir_path,
    id: scan_result.id,
    special_folder: scan_result.special_folder)
  return nil unless retro

  # Apply field updates if any
  has_field_updates = [set, add, remove].any? { |h| h && !h.empty? }
  update_retro_file(retro, set: set, add: add, remove: remove) if has_field_updates

  # Apply move if requested
  current_path = retro.path
  current_special = retro.special_folder
  if move_to
    mover = Molecules::RetroMover.new(@root_dir)
    new_path = if Ace::Support::Items::Atoms::SpecialFolderDetector.move_to_root?(move_to)
      mover.move_to_root(retro)
    else
      archive_date = parse_archive_date(retro)
      mover.move(retro, to: move_to, date: archive_date)
    end
    current_path = new_path
    current_special = Ace::Support::Items::Atoms::SpecialFolderDetector.detect_in_path(
      new_path, root: @root_dir
    )
  end

  # Reload and return updated retro
  loader.load(current_path, id: retro.id, special_folder: current_special)
end