lib/sorbet-schema/t/struct.rb in sorbet-schema-0.8.0 vs lib/sorbet-schema/t/struct.rb in sorbet-schema-0.9.0
- old
+ new
@@ -10,31 +10,29 @@
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)
+ sig { params(type: Symbol, options: T::Hash[Symbol, T.untyped]).returns(Typed::Serializer[T.untyped, T.untyped]) }
+ def serializer(type, options: {})
case type
- when :deeply_nested_hash
- Typed::HashSerializer.new(schema:, should_serialize_values: true)
when :hash
- Typed::HashSerializer.new(schema:)
+ Typed::HashSerializer.new(**T.unsafe({schema:, **options}))
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)
+ 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)
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)
+ 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