translation_serializer.rb 798 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. class REST::TranslationSerializer < ActiveModel::Serializer
  3. attributes :detected_source_language, :language, :provider, :spoiler_text, :content
  4. class PollSerializer < ActiveModel::Serializer
  5. attribute :id
  6. has_many :options
  7. def id
  8. object.status.preloadable_poll.id.to_s
  9. end
  10. def options
  11. object.poll_options
  12. end
  13. class OptionSerializer < ActiveModel::Serializer
  14. attributes :title
  15. end
  16. end
  17. has_one :poll, serializer: PollSerializer
  18. class MediaAttachmentSerializer < ActiveModel::Serializer
  19. attributes :id, :description
  20. def id
  21. object.id.to_s
  22. end
  23. end
  24. has_many :media_attachments, serializer: MediaAttachmentSerializer
  25. def poll
  26. object if object.status.preloadable_poll
  27. end
  28. end