2018-09-13 16:37:21 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class ResultSerializer < ActiveModel::Serializer
|
|
|
|
type :results
|
2018-10-07 18:36:58 +08:00
|
|
|
attributes :name, :archived
|
|
|
|
belongs_to :user, serializer: UserSerializer
|
2018-09-13 16:37:21 +08:00
|
|
|
has_one :result_text, key: :text,
|
|
|
|
serializer: ResultTextSerializer,
|
|
|
|
class_name: 'ResultText',
|
|
|
|
if: -> { object.is_text }
|
2018-10-07 18:36:58 +08:00
|
|
|
has_one :result_table, key: :table,
|
|
|
|
serializer: ResultTableSerializer,
|
|
|
|
class_name: 'ResultTable',
|
|
|
|
if: -> { object.is_table }
|
|
|
|
has_one :result_asset, key: :file,
|
|
|
|
serializer: ResultAssetSerializer,
|
|
|
|
class_name: 'ResultAsset',
|
|
|
|
if: -> { object.is_asset }
|
2018-09-13 16:37:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|