Class: WildlandHerd::PunditPolicy
- Inherits:
-
Object
- Object
- WildlandHerd::PunditPolicy
- Defined in:
- lib/wildland_herd/pundit_policy.rb
Direct Known Subclasses
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) ⇒ PunditPolicy
constructor
A new instance of PunditPolicy.
- #new? ⇒ Boolean
- #scope ⇒ Object
- #show? ⇒ Boolean
- #update? ⇒ Boolean
Constructor Details
#initialize(user, record) ⇒ PunditPolicy
Returns a new instance of PunditPolicy.
5 6 7 8 |
# File 'lib/wildland_herd/pundit_policy.rb', line 5 def initialize(user, record) @user = user @record = record end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
3 4 5 |
# File 'lib/wildland_herd/pundit_policy.rb', line 3 def record @record end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'lib/wildland_herd/pundit_policy.rb', line 3 def user @user end |
Instance Method Details
#create? ⇒ Boolean
19 20 21 |
# File 'lib/wildland_herd/pundit_policy.rb', line 19 def create? @user..limit_by_record(record).where(can_create: true).exists? end |
#destroy? ⇒ Boolean
35 36 37 |
# File 'lib/wildland_herd/pundit_policy.rb', line 35 def destroy? @user..limit_by_record(record).where(can_destroy: true).exists? end |
#edit? ⇒ Boolean
31 32 33 |
# File 'lib/wildland_herd/pundit_policy.rb', line 31 def edit? update? end |
#index? ⇒ Boolean
10 11 12 |
# File 'lib/wildland_herd/pundit_policy.rb', line 10 def index? @user..limit_by_record(record).where(can_read: true).exists? end |
#new? ⇒ Boolean
23 24 25 |
# File 'lib/wildland_herd/pundit_policy.rb', line 23 def new? create? end |
#scope ⇒ Object
39 40 41 |
# File 'lib/wildland_herd/pundit_policy.rb', line 39 def scope Pundit.policy_scope!(user, record.class) end |
#show? ⇒ Boolean
14 15 16 17 |
# File 'lib/wildland_herd/pundit_policy.rb', line 14 def show? scope.where(id: record.id).exists? && @user..limit_by_record(record).where(can_read: true).exists? end |
#update? ⇒ Boolean
27 28 29 |
# File 'lib/wildland_herd/pundit_policy.rb', line 27 def update? @user..limit_by_record(record).where(can_update: true).exists? end |