Class: Thredded::TopicPostsPageView
- Inherits:
-
Object
- Object
- Thredded::TopicPostsPageView
- Defined in:
- app/view_models/thredded/topic_posts_page_view.rb
Overview
A view model for a page of PostViews of a Topic.
Instance Attribute Summary collapse
- #topic ⇒ Thredded::BaseTopicView readonly
Instance Method Summary collapse
-
#initialize(user, topic, paginated_scope) ⇒ TopicPostsPageView
constructor
A new instance of TopicPostsPageView.
Constructor Details
#initialize(user, topic, paginated_scope) ⇒ TopicPostsPageView
Returns a new instance of TopicPostsPageView.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/view_models/thredded/topic_posts_page_view.rb', line 25 def initialize(user, topic, paginated_scope) @posts_paginator = paginated_scope @topic = "#{paginated_scope.reflect_on_association(:postable).klass}View".constantize.from_user(topic, user) prev_read = false @post_views = paginated_scope.map.with_index do |post, i| post_read = @topic.post_read?(post) post_view = Thredded::PostView.new( post, Pundit.policy!(user, post), topic_view: @topic, first_in_page: i.zero?, first_unread_in_page: !post_read && prev_read ) prev_read = post_read post_view end end |
Instance Attribute Details
#topic ⇒ Thredded::BaseTopicView (readonly)
20 21 22 |
# File 'app/view_models/thredded/topic_posts_page_view.rb', line 20 def topic @topic end |