Skip to content

Commit

Permalink
Merge pull request #792 from andyw8/andyw8/qualify-scope-class-name
Browse files Browse the repository at this point in the history
Qualify the `Scope` class name
  • Loading branch information
Burgestrand authored Jan 15, 2024
2 parents 173d85a + 98dbab8 commit 9dd0511
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Update `ApplicationPolicy`` generator to qualify the `Scope` class name (#792)

- Policy generator uses `NoMethodError` to indicate `#resolve` is not implemented (#776)

## 2.3.1 (2023-07-17)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ generator, or create your own base class to inherit from:

``` ruby
class PostPolicy < ApplicationPolicy
class Scope < Scope
class Scope < ApplicationPolicy::Scope
def resolve
if user.admin?
scope.all
Expand Down Expand Up @@ -476,7 +476,7 @@ example, associations which might be `nil`.

```ruby
class NilClassPolicy < ApplicationPolicy
class Scope < Scope
class Scope < ApplicationPolicy::Scope
def resolve
raise Pundit::NotDefinedError, "Cannot scope NilClass"
end
Expand Down
8 changes: 7 additions & 1 deletion lib/generators/pundit/policy/templates/policy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<% module_namespacing do -%>
class <%= class_name %>Policy < ApplicationPolicy
class Scope < Scope
# NOTE: Up to Pundit v2.3.1, the inheritance was declared as
# `Scope < Scope` rather than `Scope < ApplicationPolicy::Scope`.
# In most cases the behavior will be identical, but if updating existing
# code, beware of possible changes to the ancestors:
# https://gist.github.com/Burgestrand/4b4bc22f31c8a95c425fc0e30d7ef1f5

class Scope < ApplicationPolicy::Scope
# NOTE: Be explicit about which records you allow access to!
# def resolve
# scope.all
Expand Down

0 comments on commit 9dd0511

Please sign in to comment.