Sha256: a259a807971dc8717eb48ed9dbc3cd93a1e2234d938f89ebb7dd000348025c82

Contents?: true

Size: 831 Bytes

Versions: 3

Compression:

Stored size: 831 Bytes

Contents

# frozen_string_literal: true

module Thredded
  # A view model for a page of PostViews.
  class PostsPageView
    delegate :each,
             :each_with_index,
             :map,
             :size,
             :to_a,
             :to_ary,
             :present?,
             to: :@post_views
    delegate :total_pages,
             :current_page,
             :limit_value,
             to: :@posts_paginator

    # @param user [Thredded.user_class] the user who is viewing the posts page
    # @param paginated_scope [ActiveRecord::Relation<Thredded::PostCommon>] a kaminari-decorated ".page" scope
    def initialize(user, paginated_scope)
      @posts_paginator = paginated_scope
      @post_views = paginated_scope.map do |post|
        Thredded::PostView.new(post, Pundit.policy!(user, post))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thredded-1.1.0 app/view_models/thredded/posts_page_view.rb
thredded-1.0.1 app/view_models/thredded/posts_page_view.rb
thredded-1.0.0 app/view_models/thredded/posts_page_view.rb