sorbet-rails | Sorbet typechecker work with Ruby on Rails | Application Framework library
kandi X-RAY | sorbet-rails Summary
kandi X-RAY | sorbet-rails Summary
A set of tools to make the Sorbet typechecker work with Ruby on Rails seamlessly.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Create a new instance .
- Retrieve the serializer for a serializer .
- Returns a string representation of the object .
- Find ID by ID
- Array of plugin plugins
- Find one or more documents
sorbet-rails Key Features
sorbet-rails Examples and Code Snippets
Community Discussions
Trending Discussions on sorbet-rails
QUESTION
I have a PORO that I'm using as a value object. I'm adding ActiveModel via include ActiveModel::Model
for all of the niceties that that brings me. The problem is that I cannot figure out how to generate RBI files for it so that it will pass srb tc
I'm currently using sorbet-rails
and since this is a PORO and does not inherit from ActiveRecord
, bundle exec rails_rbi:all
or bundle exec rails_rbi:models
will not generate .rbi files for this even if I place it in the models dir (which it should not live in).
I could write the .rbi files by hand, but I really don't want to do that. Is there a way that I can auto generate them?
Here is a parred down example of the module I need an RBI file for
...ANSWER
Answered 2020-Sep-16 at 02:26The issue is that sorbet-typed
does not include ActiveModel::Model
which is just a wrapper around ActiveModel::Validations
and a few others. By switching to only using ActiveModel::Validations
, the code now passes typed: strict
.
The main downside to this is we don't get the nice automatic attribute assignment and still need to use an initializer. Not a big deal, but not perfect.
QUESTION
Maybe there's something in the initialization process that I missed, but sorbet-rails
seems to having trouble generating methods for some of the default rails methods (e.g. has_many
, belongs_to
, validates
, etc.). I can see that the corresponding generated association is generated, but I get type complaints that the main methods do not exist.
e.g. a class like this:
...ANSWER
Answered 2020-Jul-22 at 15:48This error is an error with sorbet
not knowing that has_and_belongs_to_many
method exists. Usually this is provided by sorbet
itself. I can see the signature of this method is defined in sorbet-typed's activerecord.rbi. In your repo it should be under this path:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install sorbet-rails
Follow the steps here to set up the latest version of Sorbet, up to being able to run srb tc.
Add sorbet-rails to your Gemfile and install them with Bundler.
Generate RBI files for your routes, models, etc
Update hidden-definition files and automatically upgrade each file's typecheck level:
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page