You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
588 B

  1. # frozen_string_literal: true
  2. class REST::PollSerializer < ActiveModel::Serializer
  3. attributes :id, :expires_at, :expired,
  4. :multiple, :votes_count
  5. has_many :loaded_options, key: :options
  6. has_many :emojis, serializer: REST::CustomEmojiSerializer
  7. attribute :voted, if: :current_user?
  8. def id
  9. object.id.to_s
  10. end
  11. def expired
  12. object.expired?
  13. end
  14. def voted
  15. object.voted?(current_user.account)
  16. end
  17. def current_user?
  18. !current_user.nil?
  19. end
  20. class OptionSerializer < ActiveModel::Serializer
  21. attributes :title, :votes_count
  22. end
  23. end