Class: Thredded::BaseTopicView

Inherits:
Object
  • Object
show all
Defined in:
app/view_models/thredded/base_topic_view.rb

Overview

A view model for TopicCommon.

Direct Known Subclasses

PrivateTopicView, TopicView

Instance Method Summary collapse

Constructor Details

#initialize(topic, read_state, policy) ⇒ BaseTopicView

Returns a new instance of BaseTopicView.

Parameters:



20
21
22
23
24
# File 'app/view_models/thredded/base_topic_view.rb', line 20

def initialize(topic, read_state, policy)
  @topic = topic
  @read_state = read_state || Thredded::NullUserTopicReadState.new(posts_count: @topic.posts_count)
  @policy = policy
end

Instance Method Details

#can_destroy?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/view_models/thredded/base_topic_view.rb', line 34

def can_destroy?
  @policy.destroy?
end

#can_update?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/view_models/thredded/base_topic_view.rb', line 30

def can_update?
  @policy.update?
end

#pathObject



38
39
40
41
42
43
44
# File 'app/view_models/thredded/base_topic_view.rb', line 38

def path
  Thredded::UrlsHelper.topic_path(
    @topic,
    page: @read_state.first_unread_post_page || @read_state.last_read_post_page,
    anchor: ('unread' if @read_state.first_unread_post_page)
  )
end

#statesObject



26
27
28
# File 'app/view_models/thredded/base_topic_view.rb', line 26

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