Sha256: f61bc47db8d401205159ed0b2ba350f89fd4bde2c838a8a2dd245d5ee113a7ac
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 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 { params(_options: T::Hash[T.untyped, T.untyped]).returns(String) } def to_json(_options = {}) Typed::JSONSerializer.new(schema: self.class.create_schema).serialize(self) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sorbet-schema-0.2.2 | lib/sorbet-schema/struct_ext.rb |
sorbet-schema-0.2.1 | lib/sorbet-schema/struct_ext.rb |