Skip to content

Commit

Permalink
Quality the Scope class name
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Jan 12, 2024
1 parent 4d8cdf1 commit bb32baf
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: Prior to Pundit v2.4.0, the inheritance was declared as
# `Scope < Scope` rather than `Scope < ApplicationPolicy`. In most cases the
# behavior will be identical, but if updating exisiting 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 bb32baf

Please sign in to comment.