Code Monkey home page Code Monkey logo

Comments (6)

hdoan741 avatar hdoan741 commented on June 25, 2024 1

I put together an PR for mailer rbi generation 😅 💦
#151

from sorbet-rails.

hdoan741 avatar hdoan741 commented on June 25, 2024

@jaredbeck, yeah, it's kind of silly that Rails ActionMailer is doing this. It is not clear how we can generate a good header for mailer though.

For example, in your case:

class UserMailer < ApplicationMailer
  def new_user_password(user)   <= sorbet-rails has no way to know the type of the argument
    # ...
  end
end

At best, we can generate the existence of the method, but we don't have information about the type of the parameters. It isn't ideal, and might get into the way of people writing actual sig for the method.

I've been advised people to write a sig for the method manually in an rbi file

# -- user_mailer.rbi
# typed: strong
class UserMailer
  sig {
    params(user: User).
    returns(ActionMailer::MessageDelivery)
  }
  def self.new_user_password(user:)
  end
end

Let me know what you think, or if you have any suggestion!

from sorbet-rails.

hdoan741 avatar hdoan741 commented on June 25, 2024

^ I think I can document this in tip & trick section, unless we have a good solution to generate sigs correctly.

If you think it's useful to generate the sig without typed param, it's doable though
eg:

class UserMailer
  sig {
    params(user: T.untyped).
    returns(ActionMailer::MessageDelivery)
  }
  def self.new_user_password(user:)
  end
end

from sorbet-rails.

jaredbeck avatar jaredbeck commented on June 25, 2024

Hi Harry, thanks for the quick response.

For example, in your case:

def new_user_password(user)  # sorbet-rails has no way to know the type of the argument

Sorry, I neglected to include the sig in my example. If we amend my example to include a signature:

sig { params(user: ::User) }
def new_user_password(user)

Does that help? Would we be able to generate an RBI with the class-method equivalent?

When the mailer action truly lacks a signature

At best, we can generate the existence of the method, but we don't have information about the type of the parameters.

If we don't generate untyped class methods, then other files that invoke said method will be limited to the typed: false sigil, right?

It [generating untyped class methods] isn't ideal, and might get into the way of people writing actual sig for the method.

Later, when write an actual sig for the instance method, we can then regenerate our RBI with rake rails_rbi:all, thus fixing the conflict, correct?

Our Options

Is this a reasonable summary of our options?

  • Do nothing - sorbet-rails will never support mailer class-methods. People will be required to write mailer RBIs by hand.
  • Generate class methods in RBI, but only if param types are known - Seems like a reasonable limitation, if documented
  • Always generate class methods, even if param types are not known - Extra effort, but helpful, assuming the eventual conflict can be fixed as described above
  • Retire from coding and take up farming

from sorbet-rails.

connorshea avatar connorshea commented on June 25, 2024

I’ve always thought potato farming looked nice

from sorbet-rails.

hdoan741 avatar hdoan741 commented on June 25, 2024

from sorbet-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.