-
Notifications
You must be signed in to change notification settings - Fork 637
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
Qualify the Scope
class name
#792
Qualify the Scope
class name
#792
Conversation
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.
This may be a matter of personal taste, but I find that having a class inheriting from another with (visually) the same name is jarring, and reduces readability, since it requires reading the surrounding context.
Thank you for the PR! I agree. I think your proposal is great. We should merge it.
However.
This changes behaviour compared to code generated before this change in a subtle way: https://gist.github.com/Burgestrand/4b4bc22f31c8a95c425fc0e30d7ef1f5
I don't think code should take advantage of < Scope
being different from < ApplicationPolicy::Scope
, but even more strongly I believe Pundit should avoid unpleasant surprises between updates.
I'm uncertain if a mere CHANGELOG entry is sufficient, and I think a comment in the generated code would be good. Generated code should always be inspected, so a comment should be sufficient to highlight this change to avoid developers being caught off-guard.
Could you please:
- Update the CHANGELOG.
- Add a comment to the policy generator template to highlight that the code might be different from previously generated policies.
cf35274
to
bb32baf
Compare
@Burgestrand thanks for the feedback! I've pushed some updates. |
I think this is good! I'll give you a chance to read the comments, and if you're up for it removing or adjusting the version specificer in the comment. Once you're happy we'll merge! |
Thanks, updated. |
bb32baf
to
98dbab8
Compare
I'd like to propose this small change to the generator, and the corresponding examples in the README. However, I'm very new to Pundit so I'm seeking input from others with more experience.
When using the generator, it results in a
Scope < Scope
inheritance, equivalent toScope < ApplicationPolicy::Scope
.This may be a matter of personal taste, but I find that having a class inheriting from another with (visually) the same name is jarring, and reduces readability, since it requires reading the surrounding context.
Additionally, this causes complications with typing system. For example, if using Sorbet:
(although it can be argued that this is a bug/limitation of Sorbet).
Looking forward to hearing some feedback.