-
Notifications
You must be signed in to change notification settings - Fork 988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subclass Options structs using a block #1489
Conversation
3850bd8
to
2a6db6d
Compare
I'm curious how well YARD can locate the classes like this. |
@olleolleolle
Edit: spoke too soon, the docs itself look weird. |
2a6db6d
to
71bbd6b
Compare
Right, so we can log a new issue about YARD overhaul for methods that should be discoverable - it takes a little bit of hand-wrangling to make "synthetic" or manually written doc blocks for code that can not be found by YARD. Help it on its way. |
It looks like YARD can handle I guess some paths forward could look like:
Edit: your reply crossed mine - I'll open a YARD issue tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @bdewater, as a Sorbet/Tapioca user myself I very much welcome this contribution 🎉 !
Unfortunately, a quick test showed that constants defined inside the structs are not behaving like before, so I've requested some changes.
As an additional note, it's worth mentioning that we've had a long standind desire to move away from structs and use proper classes instead, but this will have to be done in a future Faraday v3 release as it will hardly be backwards compatible 😅
I'd also like to introduce type signatures for Sorbet and RBS to ship with the gem ❤️
83225bf
to
a8bc317
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 🙏 !
@@ -126,18 +123,18 @@ def body=(value) | |||
|
|||
# @return [Boolean] true if status is in the set of {SuccessfulStatuses}. | |||
def success? | |||
SuccessfulStatuses.include?(status) | |||
Env::SuccessfulStatuses.include?(status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit surprised these Env::
are necessary, but it's not the end of the world 😄
I'm following the discussion in the |
As recommended on https://ruby-doc.org/core-2.2.2/Struct.html#method-c-new and https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/StructInheritance Has the nice side-effect of making the methods defined by Struct.new discoverable by Tapioca. Using the @!parse directive to ensure YARD doesn't collapse the separate pages into constants under the Faraday module
a8bc317
to
65ff26a
Compare
The directive breaks out the classes as before. Methods defined inside the block are not automatically documented anymore, but that was already the case for the accessors defined by Struct due to subclassing. |
This is already better than the inline doc generate before. @olleolleolle you're the YARD expert in the team, are you aware of any quick-fix we can take advantage of and we might be missing 😅? |
FYI -- #1490 |
Thanks for merging - that was the right call. @bdewater Thanks for keeping Faraday future-compatible! |
:reason_phrase, :response_body) do | ||
const_set(:ContentLength, 'Content-Length') | ||
const_set(:StatusesWithoutBody, Set.new([204, 304])) | ||
const_set(:SuccessfulStatuses, (200..299).freeze) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative way is to reopen the class. That way, you can define constants as usual.
Env = Options.new(:method, :request_body, :url, :request,
:request_headers, :ssl, :parallel_manager, :params,
:response, :response_headers, :status,
:reason_phrase, :response_body)
class Env
ContentLength = 'Content-Length'
StatusesWithoutBody = Set.new([204, 304])
SuccessfulStatuses = (200..299).freeze
Description
As recommended on https://ruby-doc.org/core-2.2.2/Struct.html#method-c-new and https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/StructInheritance
Has the nice side-effect of making the methods defined by
Struct.new
discoverable by Tapioca, which is how I came across the issue in the first place.Todos
N/A