Sha256: f0dc856515a13f3c4033164c85da888177fcc3c277f785c073dc2721107621a9

Contents?: true

Size: 938 Bytes

Versions: 18

Compression:

Stored size: 938 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?, :post_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

18 entries across 18 versions & 2 rubygems

Version Path
threddedDANIEL-0.14.5 app/view_models/thredded/base_topic_view.rb
thredded-0.14.4 app/view_models/thredded/base_topic_view.rb
thredded-0.14.3 app/view_models/thredded/base_topic_view.rb
thredded-0.14.2 app/view_models/thredded/base_topic_view.rb
thredded-0.14.1 app/view_models/thredded/base_topic_view.rb
thredded-0.14.0 app/view_models/thredded/base_topic_view.rb
thredded-0.13.8 app/view_models/thredded/base_topic_view.rb
thredded-0.13.7 app/view_models/thredded/base_topic_view.rb
thredded-0.13.6 app/view_models/thredded/base_topic_view.rb
thredded-0.13.5 app/view_models/thredded/base_topic_view.rb
thredded-0.13.4 app/view_models/thredded/base_topic_view.rb
thredded-0.13.3 app/view_models/thredded/base_topic_view.rb
thredded-0.13.2 app/view_models/thredded/base_topic_view.rb
thredded-0.13.1 app/view_models/thredded/base_topic_view.rb
thredded-0.13.0 app/view_models/thredded/base_topic_view.rb
thredded-0.12.4 app/view_models/thredded/base_topic_view.rb
thredded-0.12.3 app/view_models/thredded/base_topic_view.rb
thredded-0.12.2 app/view_models/thredded/base_topic_view.rb