Class: DSPy::SchemaAdapters::SorbetSchemaAdapter
- Inherits:
-
Object
- Object
- DSPy::SchemaAdapters::SorbetSchemaAdapter
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/schema_adapters.rb
Overview
Handles sorbet-schema integration for serialization/deserialization
Class Method Summary collapse
- .from_hash(struct_class, hash_data) ⇒ Object
- .to_hash(struct_instance) ⇒ Object
- .validate(struct_class, hash_data) ⇒ Object
Class Method Details
.from_hash(struct_class, hash_data) ⇒ Object
18 19 20 21 22 |
# File 'lib/dspy/schema_adapters.rb', line 18 def self.from_hash(struct_class, hash_data) # TODO: Implement using sorbet-schema # For now, fall back to direct struct creation struct_class.new(**hash_data.transform_keys(&:to_sym)) end |
.to_hash(struct_instance) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/dspy/schema_adapters.rb', line 29 def self.to_hash(struct_instance) # TODO: Implement using sorbet-schema # For now, fall back to simple serialization result = {} struct_instance.class.props.each do |name, _prop_info| result[name] = struct_instance.send(name) end result end |
.validate(struct_class, hash_data) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/dspy/schema_adapters.rb', line 45 def self.validate(struct_class, hash_data) begin result = from_hash(struct_class, hash_data) [true, result] rescue => e [false, [e.]] end end |