Class: Storytime::CommentPolicy
- Inherits:
-
Object
- Object
- Storytime::CommentPolicy
- Defined in:
- app/policies/storytime/comment_policy.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #create? ⇒ Boolean
- #destroy? ⇒ Boolean
-
#initialize(user, comment) ⇒ CommentPolicy
constructor
A new instance of CommentPolicy.
- #is_admin_or_editor? ⇒ Boolean
- #is_owner? ⇒ Boolean
- #permitted_attributes ⇒ Object
Constructor Details
#initialize(user, comment) ⇒ CommentPolicy
Returns a new instance of CommentPolicy.
5 6 7 8 |
# File 'app/policies/storytime/comment_policy.rb', line 5 def initialize(user, comment) @user = user @comment = comment end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
3 4 5 |
# File 'app/policies/storytime/comment_policy.rb', line 3 def comment @comment end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'app/policies/storytime/comment_policy.rb', line 3 def user @user end |
Instance Method Details
#create? ⇒ Boolean
18 19 20 |
# File 'app/policies/storytime/comment_policy.rb', line 18 def create? is_owner? end |
#destroy? ⇒ Boolean
22 23 24 |
# File 'app/policies/storytime/comment_policy.rb', line 22 def destroy? is_owner? || is_admin_or_editor? end |
#is_admin_or_editor? ⇒ Boolean
14 15 16 |
# File 'app/policies/storytime/comment_policy.rb', line 14 def is_admin_or_editor? (@user && (@user.storytime_admin?(@comment.site) || @user.storytime_editor?(@comment.site))) end |
#is_owner? ⇒ Boolean
10 11 12 |
# File 'app/policies/storytime/comment_policy.rb', line 10 def is_owner? @comment.user == @user end |
#permitted_attributes ⇒ Object
26 27 28 |
# File 'app/policies/storytime/comment_policy.rb', line 26 def permitted_attributes [:content] end |