Sha256: 78ea25ddc3bfb2a15c5623c1771f7776121362439c52127cb8ba4f2bc5a740f3
Contents?: true
Size: 1 KB
Versions: 5
Compression:
Stored size: 1 KB
Contents
# typed: strict module T class Struct extend T::Sig class << self extend T::Sig sig { overridable.returns(Typed::Schema) } def schema Typed::Schema.from_struct(self) end sig { params(type: Symbol).returns(Typed::Serializer[T.untyped, T.untyped]) } def serializer(type) case type when :hash Typed::HashSerializer.new(schema:) when :json Typed::JSONSerializer.new(schema:) else raise ArgumentError, "unknown serializer for #{type}" end end sig { params(serializer_type: Symbol, source: T.untyped).returns(Typed::Serializer::DeserializeResult) } def deserialize_from(serializer_type, source) serializer(serializer_type).deserialize(source) end end sig { params(serializer_type: Symbol).returns(Typed::Result[T.untyped, Typed::SerializeError]) } def serialize_to(serializer_type) self.class.serializer(serializer_type).serialize(self) end end end
Version data entries
5 entries across 5 versions & 1 rubygems