Class: Thredded::BaseTopicView
- Inherits:
-
Object
- Object
- Thredded::BaseTopicView
show all
- Defined in:
- app/view_models/thredded/base_topic_view.rb
Overview
A view model for TopicCommon.
Instance Method Summary
collapse
Constructor Details
#initialize(topic, read_state, policy) ⇒ BaseTopicView
Returns a new instance of BaseTopicView.
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
34
35
36
|
# File 'app/view_models/thredded/base_topic_view.rb', line 34
def can_destroy?
@policy.destroy?
end
|
#can_update? ⇒ Boolean
30
31
32
|
# File 'app/view_models/thredded/base_topic_view.rb', line 30
def can_update?
@policy.update?
end
|
#path ⇒ Object
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
|
#states ⇒ Object
26
27
28
|
# File 'app/view_models/thredded/base_topic_view.rb', line 26
def states
[@read_state.read? ? :read : :unread]
end
|