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:



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

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

Instance Method Details

#can_destroy?Boolean

Returns:

  • (Boolean)


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

def can_destroy?
  @policy.destroy?
end

#can_update?Boolean

Returns:

  • (Boolean)


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

def can_update?
  @policy.update?
end

#pathObject



39
40
41
# File 'app/view_models/thredded/base_topic_view.rb', line 39

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

#statesObject



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

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