ripe-article-50191
03/30/2023, 5:41 AMClass Scope < Scope inside def resolve?lemon-wall-20836
03/30/2023, 7:24 AMlemon-wall-20836
03/30/2023, 7:24 AMdef show? you have access to record and userlemon-wall-20836
03/30/2023, 7:26 AMClass Scope < Scope inside def resolve?
Not sure I understand this question thoughlemon-wall-20836
03/30/2023, 7:26 AMlemon-wall-20836
03/30/2023, 7:26 AMruby
class PostPolicy < ApplicationPolicy
class Scope
def initialize(user, scope)
@user = user
@scope = scope
end
def resolve
if user.admin?
scope.all
else
scope.where(published: true)
end
end
private
attr_reader :user, :scope
end
def update?
user.admin? or not record.published?
end
endlemon-wall-20836
03/30/2023, 7:27 AMScope class looks like from here
https://github.com/varvet/pundit#scopeslemon-wall-20836
03/30/2023, 7:27 AMresolve method you get the user and the scope which is the query passed to it (ex: User.all)