Skip to content
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

Fix docs for ActionController::Metal#headers #45362

Merged
merged 1 commit into from
Jun 18, 2022

Conversation

skipkayhil
Copy link
Member

@skipkayhil skipkayhil commented Jun 15, 2022

Summary

This documentation was correct when it was written in 6e75455, however
headers has moved a few times since:

  • added to ActionController::Http in 216309c as part of the new_base
  • Http was renamed to Metal in 52798fd
  • headers was changed from an independent hash to a delegation in
    51c7ac1 and 54becd1

Added docs for Metal#request, Metal#response, and Metal#headers that can
be linked to from Response. The recommendation to use Metal delegation
methods instead of methods on Response was also removed due to a number of
docs/guides demonstrating the opposite.

Other Information

Running CI per feedback in #45347 (comment)

I've noticed that this comment recommends using headers, status, etc. instead of response.*, but the examples in Action Controller Overview seem to use response.headers:

response.headers["Content-Type"] = "application/pdf"

Should this comment or the examples be changed to be consistent? Updated to remove this recommendation per discussion

Copy link
Member

@jonathanhefner jonathanhefner left a comment

Choose a reason for hiding this comment

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

I've noticed that this comment recommends using headers, status, etc. instead of response.*, but the examples in Action Controller Overview seem to use response.headers:
Should this comment or the examples be changed to be consistent?

I also just noticed this example (added by c83e147) too. Based on the relative age of that example and the example in the Action Controller guide (present in e56b3e4), I would say the ship has sailed, and we should remove the "should never be used directly in controllers" admonition.

And if we do that, we should probably concentrate the documentation under ActionDispatch::Response#headers, and then document ActionController::Metal#headers as simply "Delegates to ActionDispatch::Response#headers." What do you think?

@skipkayhil
Copy link
Member Author

I would say the ship has sailed, and we should remove the "should never be used directly in controllers" admonition.

attr_internal :response, :request

After looking to link to #response, I found its not actually documented because its attr_internal... should it (and #request) be documented and/or not attr_internal?)

@jonathanhefner
Copy link
Member

After looking to link to #response, I found its not actually documented because its attr_internal... should it (and #request) be documented and/or not attr_internal?)

I think it would make sense to document them as well. Perhaps something simple like "Returns an ActionDispatch::Response object for the current request."

As for attr_internal, it simply prefixes the ivar name with _ (see attr_internal_accessor). To the best of my knowledge, it doesn't have any semantic meaning regarding the public API.

@skipkayhil skipkayhil force-pushed the docs-metal-headers branch 3 times, most recently from 02980f4 to d0f56b5 Compare June 16, 2022 22:09
Comment on lines 145 to 147
##
# Returns the ActionDispatch::Response object for the current request
attr_internal :response
Copy link
Member Author

Choose a reason for hiding this comment

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

This is currently being documented as a method, but we could also mark it as an attribute which may be more accurate?

Suggested change
##
# Returns the ActionDispatch::Response object for the current request
attr_internal :response
##
# :attr_accessor: response
# Returns the ActionDispatch::Response object for the current request
attr_internal :response

Copy link
Member

Choose a reason for hiding this comment

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

Yes, perhaps so. The downside is that attributes don't show up when searching in the rendered docs sidebar. Also, attributes are linkable in the sense that references to them will become links, but attributes aren't rendered with destination anchors, so the links just go to the top of the page. I'm not sure whether those are RDoc issues or SDoc issues, though.

@jonathanhefner
Copy link
Member

After looking to link to #response, I found its not actually documented because its attr_internal... should it (and #request) be documented and/or not attr_internal?)

I hadn't actually looked, so I did not notice, but request and response are documented in ActionController::Base. Though they were documented by 2919f0d, which predates 51c7ac1. I debated whether we should prefer ActionController::Base or ActionController::Metal (or both) for documenting these things. I ended up choosing ActionController::Metal because I feel like it makes the documentation more self-consistent, but it's not a strong preference.

To get this over the finish line, I pushed a new commit. If you think it looks good, I can squash and merge. Here's what I did:

  • Remove the documentation for ActionController::Base#request and ActionController::Base#response.

  • Add :attr_reader: to ActionController::Metal#request and ActionController::Metal#response, as per your suggestion.

  • Remove the documentation for ActionController::Metal#session. It tried to link to ActionDispatch::Request#session but session is implemented by Rack, so the link did not work.

  • Some very minor tweaks to phrasing. In particular, I tried many different ways to split the documentation for ActionDispatch::Response#header and #headers (to separate the examples). But RDoc seems to ignore all directives when it sees alias_method, so I settled for the following, though I'm not sure it's actually better:

    Before After
    response-before response-after

@skipkayhil
Copy link
Member Author

  • It tried to link to ActionDispatch::Request#session but session is implemented by Rack, so the link did not work.

🤦 that's what I get for scope creeping haha, I guess I forgot to check that one

  • But RDoc seems to ignore all directives when it sees alias_method, so I settled for the following, though I'm not sure it's actually better:

Yep, I went through the same things. I like the specific mention of the alias, I think this is probably better

  • Add :attr_reader: to ActionController::Metal#request and ActionController::Metal#response, as per your suggestion.

Just double checking, I think there is a writer, but I'm not sure we should be telling people they can use it

Other than that I think everything looks good 👍

This documentation was correct when it was written in 6e75455, however
`headers` has moved a few times since:

- added to ActionController::Http in 216309c as part of the new_base
- Http was renamed to Metal in 52798fd
- headers was changed from an independent hash to a delegation in
  51c7ac1 and 54becd1

Added docs for Metal#request, Metal#response, and Metal#headers that can
be linked to from Response. The recommendation to use Metal delegation
methods instead of methods on Response was also removed due to a number of
docs/guides demonstrating the opposite.
@jonathanhefner
Copy link
Member

Just double checking, I think there is a writer, but I'm not sure we should be telling people they can use it

Yes, that is my thinking as well.

Thank you, @skipkayhil! 👋

@skipkayhil skipkayhil deleted the docs-metal-headers branch June 18, 2022 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants