Class: Guts::ApplicationPolicy Abstract
- Inherits:
-
Object
- Object
- Guts::ApplicationPolicy
- Defined in:
- app/policies/guts/application_policy.rb
Overview
This class is abstract.
Base application policies for Pundit
Direct Known Subclasses
CategoryPolicy, ContentPolicy, GroupPolicy, MediumPolicy, MetafieldPolicy, NavigationItemPolicy, NavigationPolicy, OptionPolicy, PermissionPolicy, SitePolicy, TypePolicy, UserPolicy
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#record ⇒ Object|nil
readonly
The record from the database.
-
#user ⇒ Object|nil
readonly
The user’s object.
Instance Method Summary collapse
-
#create? ⇒ Boolean
Create method policy.
-
#destroy? ⇒ Boolean
Destroy method policy.
-
#edit? ⇒ Boolean
Edit method policy.
-
#index? ⇒ Boolean
Index method policy.
-
#initialize(user, record) ⇒ ApplicationPolicy
constructor
Initilization for a policy.
-
#new? ⇒ Boolean
New method policy.
-
#scope ⇒ Object
Scope for policy.
-
#show? ⇒ Boolean
Show method policy.
-
#update? ⇒ Boolean
Update method policy.
Constructor Details
#initialize(user, record) ⇒ ApplicationPolicy
Initilization for a policy
15 16 17 18 19 20 |
# File 'app/policies/guts/application_policy.rb', line 15 def initialize(user, record) raise Pundit::NotAuthorizedError unless user @user = user @record = record end |
Instance Attribute Details
#record ⇒ Object|nil (readonly)
Returns the record from the database.
9 10 11 |
# File 'app/policies/guts/application_policy.rb', line 9 def record @record end |
#user ⇒ Object|nil (readonly)
Returns the user’s object.
6 7 8 |
# File 'app/policies/guts/application_policy.rb', line 6 def user @user end |
Instance Method Details
#create? ⇒ Boolean
Create method policy
36 37 38 |
# File 'app/policies/guts/application_policy.rb', line 36 def create? standard_check :create end |
#destroy? ⇒ Boolean
Destroy method policy
60 61 62 |
# File 'app/policies/guts/application_policy.rb', line 60 def destroy? standard_check :destory end |
#edit? ⇒ Boolean
Edit method policy
54 55 56 |
# File 'app/policies/guts/application_policy.rb', line 54 def edit? update? end |
#index? ⇒ Boolean
Index method policy
24 25 26 |
# File 'app/policies/guts/application_policy.rb', line 24 def index? standard_check :index end |
#new? ⇒ Boolean
New method policy
42 43 44 |
# File 'app/policies/guts/application_policy.rb', line 42 def new? create? end |
#scope ⇒ Object
Scope for policy
66 67 68 |
# File 'app/policies/guts/application_policy.rb', line 66 def scope Pundit.policy_scope!(user, record.class) end |
#show? ⇒ Boolean
Show method policy
30 31 32 |
# File 'app/policies/guts/application_policy.rb', line 30 def show? scope.where(id: record.id).exists? end |
#update? ⇒ Boolean
Update method policy
48 49 50 |
# File 'app/policies/guts/application_policy.rb', line 48 def update? standard_check :update end |