Class: Thredded::PostView
- Inherits:
-
Object
- Object
- Thredded::PostView
- Defined in:
- app/view_models/thredded/post_view.rb
Overview
A view model for PostCommon.
Instance Method Summary collapse
-
#cache_key ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #can_destroy? ⇒ Boolean
- #can_moderate? ⇒ Boolean
- #can_update? ⇒ Boolean
- #destroy_path ⇒ Object
- #edit_path ⇒ Object
-
#initialize(post, policy) ⇒ PostView
constructor
A new instance of PostView.
- #permalink_path ⇒ Object
Constructor Details
#initialize(post, policy) ⇒ PostView
Returns a new instance of PostView.
19 20 21 22 |
# File 'app/view_models/thredded/post_view.rb', line 19 def initialize(post, policy) @post = post @policy = policy end |
Instance Method Details
#cache_key ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/view_models/thredded/post_view.rb', line 49 def cache_key moderation_state = unless @post.private_topic_post? if @post.pending_moderation? && !Thredded.content_visible_while_pending_moderation 'p' elsif @post.blocked? '-' end end [ I18n.locale, @post, @post.user, moderation_state || '+', [ can_update?, can_destroy? ].map { |p| p ? '+' : '-' } * '' ] end |
#can_destroy? ⇒ Boolean
28 29 30 |
# File 'app/view_models/thredded/post_view.rb', line 28 def can_destroy? @can_destroy ||= @policy.destroy? end |
#can_moderate? ⇒ Boolean
32 33 34 |
# File 'app/view_models/thredded/post_view.rb', line 32 def can_moderate? @can_moderate ||= @policy.moderate? end |
#can_update? ⇒ Boolean
24 25 26 |
# File 'app/view_models/thredded/post_view.rb', line 24 def can_update? @can_update ||= @policy.update? end |
#destroy_path ⇒ Object
40 41 42 |
# File 'app/view_models/thredded/post_view.rb', line 40 def destroy_path Thredded::UrlsHelper.delete_post_path(@post) end |
#edit_path ⇒ Object
36 37 38 |
# File 'app/view_models/thredded/post_view.rb', line 36 def edit_path Thredded::UrlsHelper.edit_post_path(@post) end |
#permalink_path ⇒ Object
44 45 46 |
# File 'app/view_models/thredded/post_view.rb', line 44 def permalink_path Thredded::UrlsHelper.post_permalink_path(@post.id) end |