Class: ApplicationPolicy
- Inherits:
-
Object
show all
- Defined in:
- app/policies/application_policy.rb
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ApplicationPolicy.
4
5
6
7
|
# File 'app/policies/application_policy.rb', line 4
def initialize(user, record)
@user = user
@record = record
end
|
Instance Attribute Details
#record ⇒ Object
Returns the value of attribute record.
2
3
4
|
# File 'app/policies/application_policy.rb', line 2
def record
@record
end
|
#user ⇒ Object
Returns the value of attribute user.
2
3
4
|
# File 'app/policies/application_policy.rb', line 2
def user
@user
end
|
Instance Method Details
#create? ⇒ Boolean
21
22
23
|
# File 'app/policies/application_policy.rb', line 21
def create?
true
end
|
#destroy? ⇒ Boolean
33
34
35
|
# File 'app/policies/application_policy.rb', line 33
def destroy?
update?
end
|
#destroy_all? ⇒ Boolean
37
38
39
|
# File 'app/policies/application_policy.rb', line 37
def destroy_all?
user.admin?
end
|
#edit? ⇒ Boolean
25
26
27
|
# File 'app/policies/application_policy.rb', line 25
def edit?
update?
end
|
#index? ⇒ Boolean
13
14
15
|
# File 'app/policies/application_policy.rb', line 13
def index?
true
end
|
#new? ⇒ Boolean
17
18
19
|
# File 'app/policies/application_policy.rb', line 17
def new?
create?
end
|
#scope ⇒ Object
41
42
43
|
# File 'app/policies/application_policy.rb', line 41
def scope
Pundit.policy_scope!(user, record.class)
end
|
#show? ⇒ Boolean
9
10
11
|
# File 'app/policies/application_policy.rb', line 9
def show?
true
end
|
#update? ⇒ Boolean
29
30
31
|
# File 'app/policies/application_policy.rb', line 29
def update?
user.admin? || record.respond_to(:user) && record.user.eql?(user)
end
|