Class: Ast::Merge::UnresolvedReviewState
- Inherits:
-
Object
- Object
- Ast::Merge::UnresolvedReviewState
- Defined in:
- lib/ast/merge/unresolved_review_state.rb
Overview
Serializable unresolved-review payload for save/resume flows.
Constant Summary collapse
- SCHEMA_VERSION =
1
Instance Attribute Summary collapse
-
#cases ⇒ Object
readonly
Returns the value of attribute cases.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#schema_version ⇒ Object
readonly
Returns the value of attribute schema_version.
-
#selections ⇒ Object
readonly
Returns the value of attribute selections.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(cases:, schema_version: SCHEMA_VERSION, selections: {}, metadata: {}) ⇒ UnresolvedReviewState
constructor
A new instance of UnresolvedReviewState.
- #to_h ⇒ Object
Constructor Details
#initialize(cases:, schema_version: SCHEMA_VERSION, selections: {}, metadata: {}) ⇒ UnresolvedReviewState
Returns a new instance of UnresolvedReviewState.
31 32 33 34 35 36 37 38 |
# File 'lib/ast/merge/unresolved_review_state.rb', line 31 def initialize(cases:, schema_version: SCHEMA_VERSION, selections: {}, metadata: {}) @schema_version = schema_version.to_i @cases = Array(cases).map do |entry| entry.is_a?(Runtime::ResolutionCase) ? entry : Runtime::ResolutionCase.from_h(entry) end.freeze @selections = normalize_selections(selections) @metadata = .to_h.dup.freeze end |
Instance Attribute Details
#cases ⇒ Object (readonly)
Returns the value of attribute cases.
9 10 11 |
# File 'lib/ast/merge/unresolved_review_state.rb', line 9 def cases @cases end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/ast/merge/unresolved_review_state.rb', line 9 def @metadata end |
#schema_version ⇒ Object (readonly)
Returns the value of attribute schema_version.
9 10 11 |
# File 'lib/ast/merge/unresolved_review_state.rb', line 9 def schema_version @schema_version end |
#selections ⇒ Object (readonly)
Returns the value of attribute selections.
9 10 11 |
# File 'lib/ast/merge/unresolved_review_state.rb', line 9 def selections @selections end |
Class Method Details
.coerce(value) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/ast/merge/unresolved_review_state.rb', line 11 def self.coerce(value) case value when self then value when Hash then from_h(value) else raise ArgumentError, "unresolved review state must be a #{name} or Hash, got #{value.class}" end end |
.from_h(payload) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/ast/merge/unresolved_review_state.rb', line 21 def self.from_h(payload) payload = payload.to_h new( schema_version: payload.fetch(:schema_version, payload.fetch('schema_version', SCHEMA_VERSION)), cases: payload.fetch(:cases, payload.fetch('cases', [])), selections: payload.fetch(:selections, payload.fetch('selections', {})), metadata: payload.fetch(:metadata, payload.fetch('metadata', {})) ) end |
Instance Method Details
#to_h ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/ast/merge/unresolved_review_state.rb', line 40 def to_h { schema_version: schema_version, cases: cases.map(&:to_h), selections: selections, metadata: } end |