Comments (6)
I put together an PR for mailer rbi generation
#151
from sorbet-rails.
@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.
^ 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.
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.
I’ve always thought potato farming looked nice
from sorbet-rails.
from sorbet-rails.
Related Issues (20)
- active_record_relation.rbi ends up with false sigil HOT 4
- Cannot change default_checked_level of Sorbet when using this gem. HOT 3
- Feature: Re-generate model RBIs on db:migrate HOT 2
- Feature: custom methods on associations.
- Signatures not generated for models using new ActiveRecord::DelegatedType
- Has_many with scope on association HOT 2
- Decide whether to drop Ruby 2.4 and Ruby 2.5 HOT 2
- Feature Request: --verify option for CI HOT 1
- FR: helper_generator_class
- Method object does not exist on ActionView::Helpers::FormBuilder HOT 1
- Don't know how to build task 'rails_rbi:routes' HOT 1
- Unable to resolve constant BatchEnumerator HOT 1
- Enum override in ActiveRecordOverrides breaks with Rails 7 HOT 5
- Lots of T.nilable(T.untyped) errors after sorbet 0.5.9556
- Classic Loader issues with srb init HOT 1
- warning: already initialized constant RAILS_RBI_RAKE_DIR
- regression on update to sorbet 0.5.9892+ HOT 1
- `rails_rbi:jobs` raise unknown prefix error HOT 2
- Model with `enum` raises `ArgumentError: wrong number of arguments (given 3, expected 1)`
- Type check errors in generated RBI files HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sorbet-rails.