Class: Soba::Domain::PhaseStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/soba/domain/phase_strategy.rb

Constant Summary collapse

PHASE_TRANSITIONS =
{
  'soba:todo' => 'soba:queued',
  'soba:queued' => 'soba:planning',
  'soba:planning' => 'soba:ready',
  'soba:ready' => 'soba:doing',
  'soba:doing' => 'soba:review-requested',
  'soba:review-requested' => 'soba:reviewing',
  'soba:reviewing' => 'soba:requires-changes',
  'soba:requires-changes' => 'soba:revising',
  'soba:revising' => 'soba:review-requested',
}.freeze
PHASE_MAPPINGS =
{
  plan: { current: 'soba:todo', next: 'soba:planning' },
  queued_to_planning: { current: 'soba:queued', next: 'soba:planning' },
  implement: { current: 'soba:ready', next: 'soba:doing' },
  review: { current: 'soba:review-requested', next: 'soba:reviewing' },
  revise: { current: 'soba:requires-changes', next: 'soba:revising' },
}.freeze
IN_PROGRESS_LABELS =
%w(soba:planning soba:doing soba:reviewing soba:revising).freeze

Instance Method Summary collapse

Instance Method Details

#current_label_for_phase(phase) ⇒ Object



50
51
52
53
54
# File 'lib/soba/domain/phase_strategy.rb', line 50

def current_label_for_phase(phase)
  return nil unless phase

  PHASE_MAPPINGS.dig(phase, :current)
end

#determine_phase(labels) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/soba/domain/phase_strategy.rb', line 28

def determine_phase(labels)
  return nil if labels.blank?

  labels = labels.map(&:to_s)

  return nil if (labels & IN_PROGRESS_LABELS).any?

  return :plan if labels.include?('soba:todo')
  return :queued_to_planning if labels.include?('soba:queued')
  return :implement if labels.include?('soba:ready')
  return :review if labels.include?('soba:review-requested')
  return :revise if labels.include?('soba:requires-changes')

  nil
end

#next_label(phase) ⇒ Object



44
45
46
47
48
# File 'lib/soba/domain/phase_strategy.rb', line 44

def next_label(phase)
  return nil unless phase

  PHASE_MAPPINGS.dig(phase, :next)
end

#validate_transition(from_label, to_label) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/soba/domain/phase_strategy.rb', line 56

def validate_transition(from_label, to_label)
  if from_label.nil? || to_label.nil?
    return false
  end

  if !from_label.start_with?('soba:') || !to_label.start_with?('soba:')
    return false
  end

  # Allow direct transition from soba:todo to soba:planning (legacy path)
  if from_label == 'soba:todo' && to_label == 'soba:planning'
    return true
  end

  PHASE_TRANSITIONS[from_label] == to_label
end