2018-09-13 16:37:21 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class ResultSerializer < ActiveModel::Serializer
|
|
|
|
type :results
|
2018-09-24 22:49:27 +08:00
|
|
|
attributes :name, :user_id, :archived
|
2018-09-13 17:57:31 +08:00
|
|
|
attribute :my_module_id, key: :task_id
|
2018-09-07 21:19:20 +08:00
|
|
|
|
|
|
|
belongs_to :my_module, serializer: MyModuleSerializer
|
2018-09-13 16:37:21 +08:00
|
|
|
has_one :result_asset, key: :asset,
|
|
|
|
serializer: ResultAssetSerializer,
|
|
|
|
class_name: 'ResultAsset',
|
|
|
|
if: -> { object.is_asset }
|
|
|
|
has_one :result_table, key: :table,
|
|
|
|
serializer: ResultTableSerializer,
|
|
|
|
class_name: 'ResultTable',
|
|
|
|
if: -> { object.is_table }
|
|
|
|
has_one :result_text, key: :text,
|
|
|
|
serializer: ResultTextSerializer,
|
|
|
|
class_name: 'ResultText',
|
|
|
|
if: -> { object.is_text }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|