1
0
Fork 0
mirror of https://github.com/varvet/pundit.git synced 2022-11-09 12:30:11 -05:00

Update README to avoid subclasses Struct

Subclassing Struct unnecessarily introduces an anonymous class.
This commit is contained in:
Jeremy Weiskotten 2013-09-27 08:17:34 -04:00
parent ee6b1ed998
commit d4b3fa5aa0

View file

@ -56,7 +56,7 @@ As you can see, this is just a plain Ruby class. As a convenience, we can inheri
from Struct:
``` ruby
class PostPolicy < Struct.new(:user, :post)
PostPolicy = Struct.new(:user, :post) do
def create?
user.admin? or not post.published?
end
@ -156,8 +156,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
class PostPolicy < Struct.new(:user, :post)
class Scope < Struct.new(:user, :scope)
PostPolicy = Struct.new(:user, :post) do
Scope = Struct.new(:user, :scope) do
def resolve
if user.admin?
scope
@ -325,7 +325,7 @@ or a standard Rails 4 setup, mass-assignment protection is handled in the contro
Pundit helps you permit different attributes for different users.
```ruby
class PostPolicy < Struct.new(:user, :post)
PostPolicy = Struct.new(:user, :post) do
def permitted_attributes
if user.admin? || user.owner_of?(post)
[:title, :body]