mirror of
https://github.com/varvet/pundit.git
synced 2022-11-09 12:30:11 -05:00
Change back to inheriting from Struct
Inheriting from Struct actually has no real downsides, and the alternative makes my eyes bleed. An additional anonymous class? Who cares.
This commit is contained in:
parent
78750e6dcc
commit
631347b78b
1 changed files with 3 additions and 3 deletions
|
@ -57,7 +57,7 @@ As you can see, this is just a plain Ruby class. As a convenience, we can inheri
|
|||
from Struct or use Struct.new to define the policy class:
|
||||
|
||||
``` ruby
|
||||
PostPolicy = Struct.new(:user, :post) do
|
||||
class PostPolicy < Struct.new(:user, :post)
|
||||
def update?
|
||||
user.admin? or not post.published?
|
||||
end
|
||||
|
@ -162,8 +162,8 @@ particular user has access to. When using Pundit, you are expected to
|
|||
define a class called a policy scope. It can look something like this:
|
||||
|
||||
``` ruby
|
||||
PostPolicy = Struct.new(:user, :post) do
|
||||
self::Scope = Struct.new(:user, :scope) do
|
||||
class PostPolicy < Struct.new(:user, :post)
|
||||
class Scope < Struct.new(:user, :scope)
|
||||
def resolve
|
||||
if user.admin?
|
||||
scope.all
|
||||
|
|
Loading…
Reference in a new issue