Class: Faalis::AdminOnlyPolicy
- Inherits:
-
Object
- Object
- Faalis::AdminOnlyPolicy
- Defined in:
- app/policies/faalis/admin_only_policy.rb
Overview
This class grant admin access only. This can be a good base class for your resource if you want to give access to admin only
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #create? ⇒ Boolean
- #destroy? ⇒ Boolean
- #edit? ⇒ Boolean
- #index? ⇒ Boolean
-
#initialize(user, record) ⇒ AdminOnlyPolicy
constructor
A new instance of AdminOnlyPolicy.
- #new? ⇒ Boolean
- #scope ⇒ Object
- #show? ⇒ Boolean
- #update? ⇒ Boolean
Constructor Details
#initialize(user, record) ⇒ AdminOnlyPolicy
Returns a new instance of AdminOnlyPolicy.
7 8 9 10 |
# File 'app/policies/faalis/admin_only_policy.rb', line 7 def initialize(user, record) @user = user @record = record end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
5 6 7 |
# File 'app/policies/faalis/admin_only_policy.rb', line 5 def record @record end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
5 6 7 |
# File 'app/policies/faalis/admin_only_policy.rb', line 5 def user @user end |
Instance Method Details
#create? ⇒ Boolean
24 25 26 27 28 |
# File 'app/policies/faalis/admin_only_policy.rb', line 24 def create? return false if @user.nil? return true if @user.admin? false end |
#destroy? ⇒ Boolean
44 45 46 47 48 |
# File 'app/policies/faalis/admin_only_policy.rb', line 44 def destroy? return false if @user.nil? return true if @user.admin? false end |
#edit? ⇒ Boolean
40 41 42 |
# File 'app/policies/faalis/admin_only_policy.rb', line 40 def edit? update? end |
#index? ⇒ Boolean
12 13 14 15 16 |
# File 'app/policies/faalis/admin_only_policy.rb', line 12 def index? return false if @user.nil? return true if @user.admin? false end |
#new? ⇒ Boolean
30 31 32 |
# File 'app/policies/faalis/admin_only_policy.rb', line 30 def new? create? end |
#scope ⇒ Object
50 51 52 |
# File 'app/policies/faalis/admin_only_policy.rb', line 50 def scope Pundit.policy_scope!(@user, record.class) end |
#show? ⇒ Boolean
18 19 20 21 22 |
# File 'app/policies/faalis/admin_only_policy.rb', line 18 def show? return false if @user.nil? return true if @user.admin? false end |
#update? ⇒ Boolean
34 35 36 37 38 |
# File 'app/policies/faalis/admin_only_policy.rb', line 34 def update? return false if @user.nil? return true if @user.admin? false end |