Sha256: bb71f0e65dc6b28577e06561fe0859f44ecb4783915bd922791eac982905a5a8
Contents?: true
Size: 736 Bytes
Versions: 2
Compression:
Stored size: 736 Bytes
Contents
# typed: true module T class Struct class << self def schema Typed::Schema.from_struct(self) end def serializer(type, options: {}) case type when :hash Typed::HashSerializer.new(**T.unsafe({schema:, **options})) when :json Typed::JSONSerializer.new(schema:) else raise ArgumentError, "unknown serializer for #{type}" end end def deserialize_from(serializer_type, source, options: {}) T.unsafe(serializer(serializer_type, options:).deserialize(source)) end end def serialize_to(serializer_type, options: {}) self.class.serializer(serializer_type, options:).serialize(self) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sorbet-schema-0.9.2 | lib/sorbet-schema/t/struct.rb |
sorbet-schema-0.9.1 | lib/sorbet-schema/t/struct.rb |