Class: Geminize::Models::CodeExecution::CodeExecutionResult

Inherits:
Object
  • Object
show all
Defined in:
lib/geminize/models/code_execution/code_execution_result.rb

Overview

Represents the result of executed code

Constant Summary collapse

VALID_OUTCOMES =

Valid outcome values for code execution

["OUTCOME_OK", "OUTCOME_ERROR"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outcome, output) ⇒ CodeExecutionResult

Initialize a new code execution result

Parameters:

  • outcome (String)

    The outcome of the code execution

  • output (String)

    The output from the code execution

Raises:



21
22
23
24
25
# File 'lib/geminize/models/code_execution/code_execution_result.rb', line 21

def initialize(outcome, output)
  @outcome = outcome
  @output = output
  validate!
end

Instance Attribute Details

#outcomeString (readonly)

Returns The outcome of the code execution (e.g., "OUTCOME_OK", "OUTCOME_ERROR").

Returns:

  • (String)

    The outcome of the code execution (e.g., "OUTCOME_OK", "OUTCOME_ERROR")



12
13
14
# File 'lib/geminize/models/code_execution/code_execution_result.rb', line 12

def outcome
  @outcome
end

#outputString (readonly)

Returns The output from the code execution.

Returns:

  • (String)

    The output from the code execution



15
16
17
# File 'lib/geminize/models/code_execution/code_execution_result.rb', line 15

def output
  @output
end

Instance Method Details

#to_hHash

Alias for to_hash

Returns:

  • (Hash)

    The code execution result as a hash



66
67
68
# File 'lib/geminize/models/code_execution/code_execution_result.rb', line 66

def to_h
  to_hash
end

#to_hashHash

Convert the code execution result to a hash

Returns:

  • (Hash)

    The code execution result as a hash



57
58
59
60
61
62
# File 'lib/geminize/models/code_execution/code_execution_result.rb', line 57

def to_hash
  {
    outcome: @outcome,
    output: @output
  }
end

#validate!Boolean

Validate the code execution result

Returns:

  • (Boolean)

    true if validation passes

Raises:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/geminize/models/code_execution/code_execution_result.rb', line 30

def validate!
  unless @outcome.is_a?(String)
    raise Geminize::ValidationError.new(
      "Outcome must be a string, got #{@outcome.class}",
      "INVALID_ARGUMENT"
    )
  end

  unless VALID_OUTCOMES.include?(@outcome)
    raise Geminize::ValidationError.new(
      "Invalid outcome: #{@outcome}. Must be one of: #{VALID_OUTCOMES.join(", ")}",
      "INVALID_ARGUMENT"
    )
  end

  unless @output.is_a?(String)
    raise Geminize::ValidationError.new(
      "Output must be a string, got #{@output.class}",
      "INVALID_ARGUMENT"
    )
  end

  true
end