Sha256: bd5d0896b65ca7130571573b9639cb1fe6f82429a240a58defadfc6e85119bce

Contents?: true

Size: 833 Bytes

Versions: 2

Compression:

Stored size: 833 Bytes

Contents

# frozen_string_literal: true
require_dependency 'thredded/post_view'
require_dependency 'thredded/topic_view'
require_dependency 'thredded/private_topic_view'
module Thredded
  # A view model for a page of PostViews.
  class PostsPageView
    delegate :to_ary,
             to: :@post_views
    delegate :total_pages,
             :current_page,
             :limit_value,
             to: :@paginated_scope

    # @return [Thredded::BaseTopicView]
    attr_reader :topic

    # @param user [Thredded.user_class] the user who is viewing the posts page
    # @param paginated_scope [ActiveRecord::Relation<Thredded::PostCommon>]
    def initialize(user, paginated_scope)
      @paginated_scope = paginated_scope
      @post_views      = paginated_scope.map { |post| PostView.new(post, Pundit.policy!(user, post)) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thredded-0.5.1 app/view_models/thredded/posts_page_view.rb
thredded-0.5.0 app/view_models/thredded/posts_page_view.rb