2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-12-24 07:50:36 +08:00
|
|
|
class TopListSerializer < ApplicationSerializer
|
|
|
|
|
2021-03-30 23:42:26 +08:00
|
|
|
attributes :can_create_topic
|
2014-01-17 11:38:08 +08:00
|
|
|
|
|
|
|
def can_create_topic
|
|
|
|
scope.can_create?(Topic)
|
|
|
|
end
|
|
|
|
|
2013-12-24 07:50:36 +08:00
|
|
|
TopTopic.periods.each do |period|
|
2014-01-14 08:02:14 +08:00
|
|
|
attribute period
|
|
|
|
|
2013-12-24 07:50:36 +08:00
|
|
|
define_method(period) do
|
2019-05-07 09:57:55 +08:00
|
|
|
if resolved = object.public_send(period)
|
|
|
|
TopicListSerializer.new(resolved, scope: scope).as_json
|
2019-05-07 09:27:05 +08:00
|
|
|
end
|
2013-12-24 07:50:36 +08:00
|
|
|
end
|
2014-01-14 08:02:14 +08:00
|
|
|
|
2013-12-24 07:50:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|