Class: Comment
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Comment
- Includes:
- Checkable, HasOwner, Toggleable, VotableItem
- Defined in:
- app/models/comment.rb
Overview
Comment
Attributes:
agent_id [Agent], optional
approved [Boolean]
[String], optional
[String], optional
body [Text]
commentable_id [Integer]
commentable_type [String]
created_at [DateTime]
deleted [Boolean]
downvote_count [Integer]
ip [Inet], optional
locked [Boolean]
parent_id [Comment], optional
spam [Boolean]
updated_at [DateTime]
upvote_count [Integer]
visible [Boolean]
vote_result [Integer]
Constant Summary collapse
- AUTHOR_LIMIT =
100
- BODY_LIMIT =
1_048_576
Class Method Summary collapse
- .administrative_parameters ⇒ Object
- .creation_parameters ⇒ Object
- .entity_parameters ⇒ Object
- .page_for_administration(page = 1) ⇒ Object
- .page_for_owner(user, page = 1) ⇒ Object
- .page_for_visitor(page = 1) ⇒ Object
- .tree(collection) ⇒ Object
Instance Method Summary collapse
- #commentable_name ⇒ Object
- #commentable_title ⇒ Object
- #notify_entry_owner? ⇒ Boolean
- #profile_name ⇒ Object
- #text_for_link ⇒ Object
- #visible_to?(user) ⇒ Boolean
Class Method Details
.administrative_parameters ⇒ Object
82 83 84 |
# File 'app/models/comment.rb', line 82 def self.administrative_parameters entity_parameters + %i[deleted visible spam] end |
.creation_parameters ⇒ Object
78 79 80 |
# File 'app/models/comment.rb', line 78 def self.creation_parameters entity_parameters + %i[commentable_id commentable_type parent_id] end |
.entity_parameters ⇒ Object
74 75 76 |
# File 'app/models/comment.rb', line 74 def self.entity_parameters %i[author_name author_email body] end |
.page_for_administration(page = 1) ⇒ Object
59 60 61 |
# File 'app/models/comment.rb', line 59 def self.page_for_administration(page = 1) list_for_administration.page(page) end |
.page_for_owner(user, page = 1) ⇒ Object
70 71 72 |
# File 'app/models/comment.rb', line 70 def self.page_for_owner(user, page = 1) list_for_owner(user).page(page) end |
.page_for_visitor(page = 1) ⇒ Object
64 65 66 |
# File 'app/models/comment.rb', line 64 def self.page_for_visitor(page = 1) list_for_visitors.page(page) end |
.tree(collection) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/comment.rb', line 86 def self.tree(collection) result = {} collection.each do |entity| result[entity.id] = { parent_id: entity.parent_id, comment: entity, } end result end |
Instance Method Details
#commentable_name ⇒ Object
125 126 127 |
# File 'app/models/comment.rb', line 125 def commentable_name "#{commentable.class.model_name.human} #{commentable_id}" end |
#commentable_title ⇒ Object
129 130 131 132 133 134 135 |
# File 'app/models/comment.rb', line 129 def commentable_title if commentable.respond_to?(:title) commentable.title else commentable_name end end |
#notify_entry_owner? ⇒ Boolean
112 113 114 115 116 117 118 119 |
# File 'app/models/comment.rb', line 112 def notify_entry_owner? entry_owner = commentable.user if entry_owner.is_a?(User) && !owned_by?(entry_owner) entry_owner.can_receive_letters? else false end end |
#profile_name ⇒ Object
137 138 139 |
# File 'app/models/comment.rb', line 137 def profile_name user.nil? ? : user.profile_name end |
#text_for_link ⇒ Object
121 122 123 |
# File 'app/models/comment.rb', line 121 def text_for_link "#{self.class.model_name.human} #{id}" end |
#visible_to?(user) ⇒ Boolean
100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/models/comment.rb', line 100 def visible_to?(user) if commentable.respond_to? :visible_to? if deleted? UserPrivilege.user_has_privilege?(user, :administrator) && commentable.visible_to?(user) else commentable.visible_to?(user) end else !deleted? || UserPrivilege.user_has_privilege?(user, :administrator) end end |