varvet / pundit

Minimal authorization through OO design and pure Ruby classes
MIT License
8.27k stars 629 forks source link

Qualify the `Scope` class name #792

Closed andyw8 closed 8 months ago

andyw8 commented 9 months ago

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 to Scope < 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:

app/policies/list_policy.rb:37: Circular dependency: ListPolicy::Scope is a parent of itself https://srb.help/5011
    37 |  class Scope < Scope

(although it can be argued that this is a bug/limitation of Sorbet).

Looking forward to hearing some feedback.

andyw8 commented 8 months ago

@Burgestrand thanks for the feedback! I've pushed some updates.

Burgestrand commented 8 months ago

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!

andyw8 commented 8 months ago

Thanks, updated.