Class: Ace::Retro::Organisms::RetroManager
- Inherits:
-
Object
- Object
- Ace::Retro::Organisms::RetroManager
- 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
-
#last_folder_counts ⇒ Object
readonly
Returns the value of attribute last_folder_counts.
-
#last_list_total ⇒ Object
readonly
Returns the value of attribute last_list_total.
-
#root_dir ⇒ String
readonly
Get the root directory.
Instance Method Summary collapse
-
#create(title, type: nil, tags: [], move_to: nil) ⇒ Retro
Create a new retro.
-
#initialize(root_dir: nil, config: nil) ⇒ RetroManager
constructor
A new instance of RetroManager.
-
#list(status: nil, type: nil, in_folder: "next", tags: []) ⇒ Array<Retro>
List retros with optional filtering.
-
#show(ref) ⇒ Retro?
Show (load) a single retro by reference.
-
#update(ref, set: {}, add: {}, remove: {}, move_to: nil) ⇒ Retro?
Update a retro’s fields and optionally move to a folder.
Constructor Details
#initialize(root_dir: nil, config: nil) ⇒ RetroManager
Returns a new instance of RetroManager.
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_counts ⇒ Object (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_total ⇒ Object (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_dir ⇒ String (readonly)
Get the root directory
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
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: , move_to: move_to) end |
#list(status: nil, type: nil, in_folder: "next", tags: []) ⇒ Array<Retro>
List retros with optional filtering
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 = (retros, ) if .any? retros end |
#show(ref) ⇒ Retro?
Show (load) a single retro by reference
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.
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 |