Class: OmnifocusMcp::Tools::Operations::BatchAddItems::Planner
- Inherits:
-
Object
- Object
- OmnifocusMcp::Tools::Operations::BatchAddItems::Planner
- Defined in:
- lib/omnifocus_mcp/tools/operations/batch_add_items/planner.rb
Overview
Resolves within-batch hierarchy metadata for batch add operations.
Defined Under Namespace
Classes: Resolved
Instance Method Summary collapse
- #finalize_unresolved! ⇒ Object
-
#initialize(batch_items) ⇒ Planner
constructor
A new instance of Planner.
- #prepare! ⇒ Object
-
#processing_order ⇒ Object
Stable order: by hierarchy_level (nil -> 0), then original index.
- #record_resolution(payload:, id:, type:) ⇒ Object
-
#resolve_task_parent(payload) ⇒ Array(String?, String?, Boolean)
(parent_task_id, project_name, ready).
Constructor Details
#initialize(batch_items) ⇒ Planner
Returns a new instance of Planner.
15 16 17 18 |
# File 'lib/omnifocus_mcp/tools/operations/batch_add_items/planner.rb', line 15 def initialize(batch_items) @batch_items = batch_items @temp_resolved = {} end |
Instance Method Details
#finalize_unresolved! ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/omnifocus_mcp/tools/operations/batch_add_items/planner.rb', line 56 def finalize_unresolved! @batch_items.each do |item| next unless item.pending? item.fail!(unresolved_reason(item)) end end |
#prepare! ⇒ Object
20 21 22 23 |
# File 'lib/omnifocus_mcp/tools/operations/batch_add_items/planner.rb', line 20 def prepare! mark_cycle_failures(cycle_messages: cycle_detector.detect) mark_unknown_parent_temp_id end |
#processing_order ⇒ Object
Stable order: by hierarchy_level (nil -> 0), then original index.
26 27 28 |
# File 'lib/omnifocus_mcp/tools/operations/batch_add_items/planner.rb', line 26 def processing_order @batch_items.sort_by { |item| [item.payload.hierarchy_level || 0, item.index] } end |
#record_resolution(payload:, id:, type:) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/omnifocus_mcp/tools/operations/batch_add_items/planner.rb', line 49 def record_resolution(payload:, id:, type:) temp_id = payload.temp_id return if Utils::Blank.blank?(temp_id) @temp_resolved[temp_id] = Resolved.new(id: id, type: type, name: payload.name) end |
#resolve_task_parent(payload) ⇒ Array(String?, String?, Boolean)
Returns (parent_task_id, project_name, ready). ready is false when the task depends on a parent_temp_id that has not resolved yet, signalling a deferral.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/omnifocus_mcp/tools/operations/batch_add_items/planner.rb', line 33 def resolve_task_parent(payload) parent_task_id = payload.parent_task_id project_name = payload.project_name return [parent_task_id, project_name, true] unless need_temp_resolution?(payload) resolved = @temp_resolved[payload.parent_temp_id] return [parent_task_id, project_name, false] unless resolved if resolved.type == "project" [parent_task_id, resolved.name, true] else [resolved.id, project_name, true] end end |