Class: Ast::Merge::Runtime::ResolutionCase
- Inherits:
-
Object
- Object
- Ast::Merge::Runtime::ResolutionCase
- Defined in:
- lib/ast/merge/runtime/resolution_case.rb
Overview
Reviewable unresolved merge case surfaced by a runtime merge operation.
Instance Attribute Summary collapse
-
#candidates ⇒ Object
readonly
Returns the value of attribute candidates.
-
#case_id ⇒ Object
readonly
Returns the value of attribute case_id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#operation_id ⇒ Object
readonly
Returns the value of attribute operation_id.
-
#provisional_winner ⇒ Object
readonly
Returns the value of attribute provisional_winner.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#surface_path ⇒ Object
readonly
Returns the value of attribute surface_path.
Class Method Summary collapse
Instance Method Summary collapse
- #candidate_for(selection = provisional_winner) ⇒ Object
-
#initialize(case_id:, reason:, candidates:, provisional_winner: nil, surface_path: nil, operation_id: nil, metadata: {}) ⇒ ResolutionCase
constructor
A new instance of ResolutionCase.
- #selected_candidate ⇒ Object
- #to_h ⇒ Object
- #unresolved? ⇒ Boolean
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
#candidates ⇒ Object (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_id ⇒ Object (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 |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
21 22 23 |
# File 'lib/ast/merge/runtime/resolution_case.rb', line 21 def @metadata end |
#operation_id ⇒ Object (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_winner ⇒ Object (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 |
#reason ⇒ Object (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_path ⇒ Object (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_candidate ⇒ Object
53 54 55 |
# File 'lib/ast/merge/runtime/resolution_case.rb', line 53 def selected_candidate candidate_for(provisional_winner) end |
#to_h ⇒ Object
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
49 50 51 |
# File 'lib/ast/merge/runtime/resolution_case.rb', line 49 def unresolved? true end |