Class: Thredded::BaseUserTopicDecorator
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Thredded::BaseUserTopicDecorator
show all
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion
- Defined in:
- app/decorators/thredded/base_user_topic_decorator.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
25
26
27
28
29
|
# File 'app/decorators/thredded/base_user_topic_decorator.rb', line 25
def initialize(user, topic)
@user = user || Thredded::NullUser.new
@topic = self.class.decorator_class.new(topic)
super(@topic)
end
|
Class Method Details
.decorate_all(user, topics) ⇒ Object
16
17
18
|
# File 'app/decorators/thredded/base_user_topic_decorator.rb', line 16
def decorate_all(user, topics)
topics.map { |topic| new(user, topic) }
end
|
.decorator_class ⇒ Object
12
13
14
|
# File 'app/decorators/thredded/base_user_topic_decorator.rb', line 12
def decorator_class
"#{topic_class.name}Decorator".constantize
end
|
.model_name ⇒ Object
20
21
22
|
# File 'app/decorators/thredded/base_user_topic_decorator.rb', line 20
def model_name
ActiveModel::Name.new(self, nil, topic_class.name.demodulize)
end
|
.topic_class ⇒ Class<ActiveRecord::Base>
8
9
10
|
# File 'app/decorators/thredded/base_user_topic_decorator.rb', line 8
def topic_class
fail 'Implement in subclass'
end
|
Instance Method Details
#css_class ⇒ Object
39
40
41
|
# File 'app/decorators/thredded/base_user_topic_decorator.rb', line 39
def css_class
[read_status_class, topic.css_class].map(&:presence).compact.join(' ')
end
|
#persisted? ⇒ Boolean
35
36
37
|
# File 'app/decorators/thredded/base_user_topic_decorator.rb', line 35
def persisted?
false
end
|
#read? ⇒ Boolean
51
52
53
|
# File 'app/decorators/thredded/base_user_topic_decorator.rb', line 51
def read?
fail 'Subclass responsibility'
end
|
#read_status_class ⇒ Object
43
44
45
46
47
48
49
|
# File 'app/decorators/thredded/base_user_topic_decorator.rb', line 43
def read_status_class
if read?
'thredded--topic--read'
else
'thredded--topic--unread'
end
end
|
#to_ary ⇒ Object
55
56
57
|
# File 'app/decorators/thredded/base_user_topic_decorator.rb', line 55
def to_ary
[self]
end
|
#to_model ⇒ Object
31
32
33
|
# File 'app/decorators/thredded/base_user_topic_decorator.rb', line 31
def to_model
topic
end
|