Class: DSPy::Signature::StructBuilder
- Inherits:
-
Object
- Object
- DSPy::Signature::StructBuilder
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/signature.rb
Overview
DSL helper for building struct classes with field descriptions
Instance Attribute Summary collapse
-
#field_descriptors ⇒ Object
readonly
Returns the value of attribute field_descriptors.
Instance Method Summary collapse
- #build_struct_class ⇒ Object
- #const(name, type, **kwargs) ⇒ Object
-
#initialize ⇒ StructBuilder
constructor
A new instance of StructBuilder.
Constructor Details
#initialize ⇒ StructBuilder
Returns a new instance of StructBuilder.
43 44 45 |
# File 'lib/dspy/signature.rb', line 43 def initialize @field_descriptors = {} end |
Instance Attribute Details
#field_descriptors ⇒ Object (readonly)
Returns the value of attribute field_descriptors.
40 41 42 |
# File 'lib/dspy/signature.rb', line 40 def field_descriptors @field_descriptors end |
Instance Method Details
#build_struct_class ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dspy/signature.rb', line 56 def build_struct_class descriptors = @field_descriptors Class.new(T::Struct) do extend T::Sig descriptors.each do |name, descriptor| if descriptor.has_default const name, descriptor.type, default: descriptor.default_value else const name, descriptor.type end end end end |
#const(name, type, **kwargs) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/dspy/signature.rb', line 48 def const(name, type, **kwargs) description = kwargs[:description] has_default = kwargs.key?(:default) default_value = kwargs[:default] @field_descriptors[name] = FieldDescriptor.new(type, description, has_default, default_value) end |