Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Docs: signatures for methods returning relations #214

Merged
merged 4 commits into from
Nov 12, 2019

Conversation

jaredbeck
Copy link
Contributor

I couldn't find any docs on this, so I'm attempting to write some. I'm not at all sure this is correct, but will at least start a conversation. Thanks!

@hdoan741
Copy link
Contributor

hdoan741 commented Oct 25, 2019 via email

@jaredbeck
Copy link
Contributor Author

we do support using Bacon::ActiveRecord_Relation ..

Oh, great! Should I update this PR to make that the recommendation?

@hdoan741
Copy link
Contributor

Sure, I think we need it. Hopefully we can resolve the issue like with #211

Thanks for helping with the documentation. Here is some thought I've had:

  • We need a whole section calling out things sorbet-rails provide at runtime (as opposed to things provided via the static generator). It includes following functionality:
  • Relation class: Making the relations available at runtime (they are private, the gem make them public)
  • Model: find_n, first_n, last_n are the methods we added. pluck_to_tstruct as well.
  • Controller: adding fetch_typed and require_typed
  • And make sure people put sorbet-rails in a common group in their Gemfile (not development or test only)

@jaredbeck
Copy link
Contributor Author

Here is some thought I've had

Nice! Thanks Harry. I've added your thoughts, and re-organized a little.

@codecov-io
Copy link

codecov-io commented Oct 25, 2019

Codecov Report

Merging #214 into master will increase coverage by 0.08%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #214      +/-   ##
==========================================
+ Coverage   96.14%   96.22%   +0.08%     
==========================================
  Files         138      138              
  Lines        2228     2228              
==========================================
+ Hits         2142     2144       +2     
+ Misses         86       84       -2
Impacted Files Coverage Δ
lib/sorbet-rails/model_rbi_formatter.rb 93.75% <0%> (+3.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 12151d4...996b5f4. Read the comment docs.

@jaredbeck jaredbeck force-pushed the patch-2 branch 2 times, most recently from 50b1161 to f5fe551 Compare October 25, 2019 23:09
Copy link
Contributor

@hdoan741 hdoan741 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I provided some feedback. Please let me know what you think

README.md Outdated
@@ -19,16 +19,14 @@ This gem adds a few Rake tasks to generate Ruby Interface (RBI) files for dynami

```
# -- Gemfile --

# In the default group (same as sorbet-runtime) because of "Features Provided at Runtime" below
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've heard some people don't use sorbet-runtime in the production environment, so I think this part may actually be misleading. Maybe we should say "the group including production environment"

README.md Outdated
@@ -148,6 +146,22 @@ Since mailing action methods is based on instance methods defined in a mailer cl
- If not, all the params in the mailing action method will be T.untyped.
- For return type though, the mailing action method will return `ActionMailer::MessageDelivery` instead of the return type of the instance method.

## Features Provided at Runtime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change the current "Type-checking Rails code" to "Static RBI Generation", and move the documentation of run-time features there to this section.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's needed for this section to work properly is running rake rails_rbi:custom, which will copy the rbi for the provided methods.

@jaredbeck
Copy link
Contributor Author

Updated per comments, please review.

What's needed for this section to work properly is running rake rails_rbi:custom, which will copy the rbi for the provided methods.

I don't understand this comment. Is it something you can add in a future PR?

Copy link
Contributor

@hdoan741 hdoan741 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :-) I suggested a title so that it's parallel with the "Static RBI Generation" title

README.md Outdated
@@ -148,6 +147,23 @@ Since mailing action methods is based on instance methods defined in a mailer cl
- If not, all the params in the mailing action method will be T.untyped.
- For return type though, the mailing action method will return `ActionMailer::MessageDelivery` instead of the return type of the instance method.

### Features Provided at Runtime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Features Provided at Runtime
## Runtime Features

@hdoan741
Copy link
Contributor

hdoan741 commented Nov 7, 2019

Btw, please remove [ci skip] from your commit message. Github checks the PR passes the Travis CI check before it can be merged. Our repo is set up to requires PR passes CI run to merge. Even though this change doesn't make any code change, it's easier to have consistent rule on this.

@hdoan741
Copy link
Contributor

hdoan741 commented Nov 7, 2019

I don't understand this comment. Is it something you can add in a future PR?

Sure, I'll add it later. I'll attempt to explain it still: simply put we need to copy some RBI so that the sorbet knows the signature of the runtime methods added. It's through running the rake task

rake rails_rbi:custom

@jaredbeck
Copy link
Contributor Author

Thanks Harry, changes made.

@hdoan741 hdoan741 merged commit 3c2fa85 into chanzuckerberg:master Nov 12, 2019
@jaredbeck jaredbeck deleted the patch-2 branch June 15, 2020 22:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants