I can't find any examples of how to deal with attributes that are serialized columns.
class MyClass < ApplicationRecord
serialize :related_pages, Array
end
In this case, it is an Array of String (eg T::Array[String]).
The only solution I have found is to cast it: T.cast(related_pages, T::Array[String])
Is this the best solution?
Unfortunately, I don't think there's a good way to automatically get what you want right now. I'd say to use Tapioca, but it looks like it generates untyped getters and setters for
serializecalls, which won't help you. If you feel confident in Tapioca, I suppose you could write your own DSL compiler, but that's its own can of worms.That said, there is a way to get around this manually that doesn't involve
T.cast: you can write your own.rbifiles. It has some problems (e.g. you have to keep them in sync yourself, and you're basically asserting to the type checker that you know what you're doing) but it's a possibility!For yours, I think it'd look like this (I haven't run this; it's just for illustration):