Class: Retab::Types::BaseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/retab/types/base_model.rb

Direct Known Subclasses

Actor, AllItemsMatchCondition, AnyItemMatchesCondition, ApiCallAttempt, ApiCallInvocation, ApiTrigger, ApproveReviewRequest, ArrayContainsCondition, AssertionFailure, AssertionResult, AssertionSchemaDep, AssertionSpec, AwaitingReviewRun, AwaitingReviewStepLifecycle, BBox, BetweenCondition, BlockTestBatchExecutionCounts, BlockTestLifecycleCounts, BlockTestOutcomeCounts, CancelWorkflowExperimentRunResponse, CancelWorkflowRequest, CancelWorkflowResponse, CancelledStepLifecycle, CancelledTerminal, Category, Classification, ClassificationConsensus, ClassificationDecision, ClassificationRequest, ClassificationWorkflowArtifact, CompleteFileUploadRequest, CompletedBlockExecutionLifecycle, ConditionEvaluationDetails, ConditionEvaluationPerItem, ConditionEvaluationResult, ConditionEvaluationSubCondition, ConditionalEvaluation, ContainCondition, ContainerContextData, CreateBlockExecutionRequest, CreateEditTemplateRequest, CreateExperimentRequest, CreateExperimentRunRequest, CreateJobRequest, CreateReviewVersionRequest, CreateUploadResponse, CreateWorkflowRequest, CreateWorkflowRunRequest, CreateWorkflowTestRequest, CreateWorkflowTestRunRequest, DeclarativeApplyResponse, DeclarativeExportResponse, DeclarativePlanChange, DeclarativePlanFieldChange, DeclarativePlanResourceChange, DeclarativePlanResponse, DeclarativePlanSummary, DeclarativeValidationResponse, DeclarativeWorkflowRequest, Edit, EditConfig, EditRequest, EditResult, EditTemplate, EditWorkflowArtifact, EmailTrigger, EndsWithCondition, EqualCondition, ErrorBlockExecutionLifecycle, ErrorDetails, ErrorStepLifecycle, ErrorTerminal, ErrorWorkflowExperimentResult, ExistCondition, ExperimentByDocumentMetricsResponse, ExperimentByDocumentTargetMetric, ExperimentByTargetDocumentMetric, ExperimentByTargetMetricsResponse, ExperimentConfusionFlowMetric, ExperimentConfusionSummaryAggregate, ExperimentDocumentCaptureRequest, ExperimentDocumentProvenance, ExperimentExtractSummaryAggregate, ExperimentMetricDocumentRef, ExperimentMetricsMissingError, ExperimentMetricsStaleError, ExperimentResult, ExperimentResultTiming, ExperimentRun, ExperimentRunTiming, ExperimentRunTrigger, ExperimentSummaryMetricDocument, ExperimentSummaryMetricsResponse, ExperimentTargetConfusionMetric, ExperimentVoteRow, ExperimentVotesMetricsResponse, ExplicitExperimentDocumentRequest, Extraction, ExtractionConsensus, ExtractionRequest, ExtractionWorkflowArtifact, FileHandleInput, FileLink, FileModel, FileRef, FormField, FunctionInvocation, GenerateSchemaRequest, HandlePayload, HttpValidationError, Job, JobError, JobResponse, JsonHandleInput, JsonSchemaValidCondition, LatestBlockTestRunSummary, LengthCompareCondition, LlmJudgedAsCondition, LlmNotJudgedAsCondition, ManualTrigger, ManualWorkflowTestSource, MatcheRegexCondition, MaterializedDocument, MetricsStaleErrorLastRun, NotContainsCondition, NotEqualsCondition, NotExistsCondition, NumberCompareCondition, ObjectContainsCondition, OutputTarget, Parse, ParseOutput, ParseRequest, ParseWorkflowArtifact, PartialSchema, Partition, PartitionChunk, PartitionChunkLikelihood, PartitionConsensus, PartitionRequest, PartitionWorkflowArtifact, PendingRun, PublishWorkflowRequest, QueuedStepLifecycle, RejectReviewRequest, RestartTrigger, RetabUsage, Review, ReviewAllOf, ReviewAlways, ReviewAnyOf, ReviewAnyRequiredFieldNull, ReviewAnySplitPagesLt, ReviewBoundaryConfidenceLt, ReviewBranchIn, ReviewCategoryIn, ReviewConfidenceLt, ReviewDecision, ReviewEvaluation, ReviewFieldConfidenceLt, ReviewJsonCondition, ReviewSplitCountNeq, ReviewTopMarginLt, ReviewValidationFailed, ReviewVersion, RunInputs, RunStepWorkflowTestSource, RunTiming, RunningRun, ScheduleTrigger, SimilarityGteCondition, SkippedBlockExecutionLifecycle, SourcesResponse, Split, SplitConsensus, SplitIouCondition, SplitRequest, SplitResult, SplitSubdocumentLikelihood, SplitWorkflowArtifact, StartWithCondition, StepArtifactRef, StoredBlockExecution, Subdocument, SubmitDecisionResponse, UpdateEditTemplateRequest, UpdateExperimentRequest, UpdateWorkflowBlockRequest, UpdateWorkflowRequest, UpdateWorkflowTestRequest, UploadFileRequest, ValidationError, VerdictSummary, WebhookTrigger, WhileLoopTermination, Workflow, WorkflowArtifact, WorkflowBlock, WorkflowBlockCreateRequest, WorkflowEdgeCreateRequest, WorkflowEdgeDoc, WorkflowExperiment, WorkflowExportPayloadRequest, WorkflowExportPayloadResponse, WorkflowPublished, WorkflowRun, WorkflowRunStep, WorkflowSnapshotRef, WorkflowTest, WorkflowTestBlockTarget, WorkflowTestResult, WorkflowTestRun, WorkflowTestRunBlockScope, WorkflowTestRunSingleScope, WorkflowTestRunTiming, WorkflowTestRunWorkflowScope

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_responseObject

Returns the value of attribute last_response.



28
29
30
# File 'lib/retab/types/base_model.rb', line 28

def last_response
  @last_response
end

Class Method Details

.deep_symbolize(value) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/retab/types/base_model.rb', line 46

def self.deep_symbolize(value)
  case value
  when Hash
    value.each_with_object({}) { |(k, v), h| h[k.to_sym] = deep_symbolize(v) }
  when Array
    value.map { |v| deep_symbolize(v) }
  else
    value
  end
end

.normalize(json) ⇒ Object

Normalize incoming ‘json` into a Hash with symbol keys (all the way down). The spec-derived `initialize` body reads `hash` and passes nested values to other model constructors / discriminator `case … when “api” then` dispatchers. The String branch already symbolizes deeply via `JSON.parse(…, symbolize_names: true)`; the Hash branch must match — otherwise list responses (which arrive as string-keyed Hashes from `ListStruct.from_response`’s ‘JSON.parse`) leave nested data unsymbolized and the discriminator falls through to the raw `else` branch instead of constructing the typed variant.

Raises:

  • (ArgumentError)


39
40
41
42
43
44
# File 'lib/retab/types/base_model.rb', line 39

def self.normalize(json)
  return {} if json.nil?
  return deep_symbolize(json) if json.is_a?(Hash)
  return JSON.parse(json, symbolize_names: true) if json.is_a?(String)
  raise ArgumentError, "cannot normalize #{json.class} into a model hash"
end

Instance Method Details

#inspectObject



72
73
74
75
# File 'lib/retab/types/base_model.rb', line 72

def inspect
  attrs = to_h.map { |k, v| "#{k}=#{v.inspect}" }.join(" ")
  "#<#{self.class.name} #{attrs}>"
end

#to_hObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/retab/types/base_model.rb', line 57

def to_h
  hash_attrs = self.class.const_defined?(:HASH_ATTRS) ? self.class.const_get(:HASH_ATTRS) : {}
  out = {}
  hash_attrs.each do |wire_key, attr|
    value = instance_variable_get("@#{attr}")
    out[wire_key] = serialize(value)
  end

  out
end

#to_json(*args) ⇒ Object



68
69
70
# File 'lib/retab/types/base_model.rb', line 68

def to_json(*args)
  to_h.to_json(*args)
end