Sha256: a79c38e59c051532fc11e2bbabcd550f91e9a4e654ec390378883a47b840d709

Contents?: true

Size: 924 Bytes

Versions: 5

Compression:

Stored size: 924 Bytes

Contents

# frozen_string_literal: true
module Thredded
  # A view model for TopicCommon.
  class BaseTopicView
    delegate :title,
             :posts_count,
             :last_post_at,
             :created_at,
             :user,
             :last_user,
             :to_model,
             to: :@topic

    delegate :read?,
             to: :@read_state

    # @param topic [TopicCommon]
    # @param read_state [UserTopicReadStateCommon, nil]
    # @param policy [#destroy?]
    def initialize(topic, read_state, policy)
      @read_state = read_state || Thredded::NullUserTopicReadState.new
      @topic      = topic
      @policy     = policy
    end

    def states
      [@read_state.read? ? :read : :unread]
    end

    def can_update?
      @policy.update?
    end

    def can_destroy?
      @policy.destroy?
    end

    def path
      Thredded::UrlsHelper.topic_path(@topic, page: @read_state.page)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
thredded-0.10.0 app/view_models/thredded/base_topic_view.rb
thredded-0.9.4 app/view_models/thredded/base_topic_view.rb
thredded-0.9.3 app/view_models/thredded/base_topic_view.rb
thredded-0.9.2 app/view_models/thredded/base_topic_view.rb
thredded-0.9.1 app/view_models/thredded/base_topic_view.rb