lib/sorbet-schema/t/struct.rb in sorbet-schema-0.9.0 vs lib/sorbet-schema/t/struct.rb in sorbet-schema-0.9.1
- old
+ new
@@ -1,20 +1,14 @@
-# typed: strict
+# typed: true
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, options: T::Hash[Symbol, T.untyped]).returns(Typed::Serializer[T.untyped, T.untyped]) }
def serializer(type, options: {})
case type
when :hash
Typed::HashSerializer.new(**T.unsafe({schema:, **options}))
when :json
@@ -22,16 +16,14 @@
else
raise ArgumentError, "unknown serializer for #{type}"
end
end
- sig { params(serializer_type: Symbol, source: T.untyped, options: T::Hash[Symbol, T.untyped]).returns(Typed::Serializer::DeserializeResult) }
def deserialize_from(serializer_type, source, options: {})
- serializer(serializer_type, options:).deserialize(source)
+ T.unsafe(serializer(serializer_type, options:).deserialize(source))
end
end
- sig { params(serializer_type: Symbol, options: T::Hash[Symbol, T.untyped]).returns(Typed::Result[T.untyped, Typed::SerializeError]) }
def serialize_to(serializer_type, options: {})
self.class.serializer(serializer_type, options:).serialize(self)
end
end
end