Sorbet-friendly attachment declarations


Users adding Sorbet to their codebase are immediately greeted with type checker warnings:

app/models/editorial.rb:5: include must only contain constant literals
     5 |  include

This is because Sorbet doesn’t support dynamic includes like this (I can’t include links as a new user but look at the link in the code snippet above or Adopting Sorbet section within their docs page).


Add an alternative way to add attachments to a model for Sorbet users.

Something like:

class Photo < Sequel::Model
  include Shrine::Attachment

  # Proposed new method
  attachment_name :image

From a cursory glance at the codebase I didn’t see anything that would make this impossible/very hard to do but thought @janko and other contributors will have more context.

Hi @janklimo :wave:

It would be nice to find a Sorbet-friendly syntax. In your proposed way, would it be possible to use different uploaders for different attachments? Something like this in current syntax:

class Profile < Sequel::Model

Thank you for your response @janko!

In fact this proposal won’t be relevant. As I learned later, you can do the following to get around compiler warnings:

class Profile < Sequel::Model
  Attachment =
  include Attachment