Class: Geminize::Models::CodeExecution::ExecutableCode
- Inherits:
-
Object
- Object
- Geminize::Models::CodeExecution::ExecutableCode
- Defined in:
- lib/geminize/models/code_execution/executable_code.rb
Overview
Represents executable code generated by the model
Constant Summary collapse
- VALID_LANGUAGES =
Valid language options for executable code
["PYTHON"].freeze
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
The code content.
-
#language ⇒ String
readonly
The language of the code (e.g., "PYTHON").
Instance Method Summary collapse
-
#initialize(language, code) ⇒ ExecutableCode
constructor
Initialize a new executable code object.
-
#to_h ⇒ Hash
Alias for to_hash.
-
#to_hash ⇒ Hash
Convert the executable code to a hash.
-
#validate! ⇒ Boolean
Validate the executable code.
Constructor Details
#initialize(language, code) ⇒ ExecutableCode
Initialize a new executable code object
21 22 23 24 25 |
# File 'lib/geminize/models/code_execution/executable_code.rb', line 21 def initialize(language, code) @language = language @code = code validate! end |
Instance Attribute Details
#code ⇒ String (readonly)
15 16 17 |
# File 'lib/geminize/models/code_execution/executable_code.rb', line 15 def code @code end |
#language ⇒ String (readonly)
12 13 14 |
# File 'lib/geminize/models/code_execution/executable_code.rb', line 12 def language @language end |
Instance Method Details
#to_h ⇒ Hash
Alias for to_hash
66 67 68 |
# File 'lib/geminize/models/code_execution/executable_code.rb', line 66 def to_h to_hash end |
#to_hash ⇒ Hash
Convert the executable code to a hash
57 58 59 60 61 62 |
# File 'lib/geminize/models/code_execution/executable_code.rb', line 57 def to_hash { language: @language, code: @code } end |
#validate! ⇒ Boolean
Validate the executable code
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/executable_code.rb', line 30 def validate! unless @language.is_a?(String) raise Geminize::ValidationError.new( "Language must be a string, got #{@language.class}", "INVALID_ARGUMENT" ) end unless VALID_LANGUAGES.include?(@language) raise Geminize::ValidationError.new( "Invalid language: #{@language}. Must be one of: #{VALID_LANGUAGES.join(", ")}", "INVALID_ARGUMENT" ) end unless @code.is_a?(String) raise Geminize::ValidationError.new( "Code must be a string, got #{@code.class}", "INVALID_ARGUMENT" ) end true end |