Sha256: 21c36d0d82006e4062e742462bf69418bda4c4ba5a82aa2c1ad9abb53c2cb287
Contents?: true
Size: 1.04 KB
Versions: 3
Compression:
Stored size: 1.04 KB
Contents
# typed: strict module T class Struct extend T::Sig sig { returns(Typed::Schema) } def self.create_schema Typed::Schema.new( target: self, fields: props.map do |name, properties| Typed::Field.new(name: name, type: properties[:type], required: !properties[:fully_optional]) end ) end sig { params(hash: Typed::HashSerializer::InputHash).returns(Typed::Serializer::DeserializeResult) } def self.from_hash(hash) Typed::HashSerializer.new(schema: create_schema).deserialize(hash) end sig { params(json: String).returns(Typed::Serializer::DeserializeResult) } def self.from_json(json) Typed::JSONSerializer.new(schema: create_schema).deserialize(json) end sig { returns(Typed::HashSerializer::OutputHash) } def to_hash Typed::HashSerializer.new(schema: self.class.create_schema).serialize(self) end sig { returns(String) } def to_json Typed::JSONSerializer.new(schema: self.class.create_schema).serialize(self) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sorbet-schema-0.2.0 | lib/sorbet-schema/struct_ext.rb |
sorbet-schema-0.1.1 | lib/sorbet-schema/struct_ext.rb |
sorbet-schema-0.1.0 | lib/sorbet-schema/struct_ext.rb |