Class: Ast::Merge::Runtime::ResolutionCase

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/merge/runtime/resolution_case.rb

Overview

Reviewable unresolved merge case surfaced by a runtime merge operation.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(case_id:, reason:, candidates:, provisional_winner: nil, surface_path: nil, operation_id: nil, metadata: {}) ⇒ ResolutionCase

Returns a new instance of ResolutionCase.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ast/merge/runtime/resolution_case.rb', line 29

def initialize(
  case_id:,
  reason:,
  candidates:,
  provisional_winner: nil,
  surface_path: nil,
  operation_id: nil,
  metadata: {}
)
  @case_id = case_id.to_s
  @reason = reason.to_sym
  @candidates = normalize_candidates(candidates)
  @provisional_winner = provisional_winner&.to_sym
  @surface_path = surface_path
  @operation_id = operation_id
  @metadata = .dup.freeze

  validate_provisional_winner!
end

Instance Attribute Details

#candidatesObject (readonly)

Returns the value of attribute candidates.



21
22
23
# File 'lib/ast/merge/runtime/resolution_case.rb', line 21

def candidates
  @candidates
end

#case_idObject (readonly)

Returns the value of attribute case_id.



21
22
23
# File 'lib/ast/merge/runtime/resolution_case.rb', line 21

def case_id
  @case_id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



21
22
23
# File 'lib/ast/merge/runtime/resolution_case.rb', line 21

def 
  @metadata
end

#operation_idObject (readonly)

Returns the value of attribute operation_id.



21
22
23
# File 'lib/ast/merge/runtime/resolution_case.rb', line 21

def operation_id
  @operation_id
end

#provisional_winnerObject (readonly)

Returns the value of attribute provisional_winner.



21
22
23
# File 'lib/ast/merge/runtime/resolution_case.rb', line 21

def provisional_winner
  @provisional_winner
end

#reasonObject (readonly)

Returns the value of attribute reason.



21
22
23
# File 'lib/ast/merge/runtime/resolution_case.rb', line 21

def reason
  @reason
end

#surface_pathObject (readonly)

Returns the value of attribute surface_path.



21
22
23
# File 'lib/ast/merge/runtime/resolution_case.rb', line 21

def surface_path
  @surface_path
end

Class Method Details

.from_h(payload) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ast/merge/runtime/resolution_case.rb', line 8

def self.from_h(payload)
  payload = payload.to_h
  new(
    case_id: payload.key?(:case_id) ? payload[:case_id] : payload.fetch('case_id'),
    reason: payload.key?(:reason) ? payload[:reason] : payload.fetch('reason'),
    candidates: payload.key?(:candidates) ? payload[:candidates] : payload.fetch('candidates'),
    provisional_winner: payload[:provisional_winner] || payload['provisional_winner'],
    surface_path: payload[:surface_path] || payload['surface_path'],
    operation_id: payload[:operation_id] || payload['operation_id'],
    metadata: payload.fetch(:metadata, payload.fetch('metadata', {}))
  )
end

Instance Method Details

#candidate_for(selection = provisional_winner) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/ast/merge/runtime/resolution_case.rb', line 57

def candidate_for(selection = provisional_winner)
  return if selection.nil?

  candidates.fetch(selection.to_sym) do
    raise ArgumentError,
          "selection #{selection.inspect} must be present in candidates"
  end
end

#selected_candidateObject



53
54
55
# File 'lib/ast/merge/runtime/resolution_case.rb', line 53

def selected_candidate
  candidate_for(provisional_winner)
end

#to_hObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ast/merge/runtime/resolution_case.rb', line 66

def to_h
  {
    case_id: case_id,
    reason: reason,
    candidates: candidates,
    provisional_winner: provisional_winner,
    surface_path: surface_path,
    operation_id: operation_id,
    metadata: 
  }.compact
end

#unresolved?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/ast/merge/runtime/resolution_case.rb', line 49

def unresolved?
  true
end