custom_emoji_serializer.rb 500 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class REST::CustomEmojiSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :shortcode, :url, :static_url, :visible_in_picker
  5. attribute :category, if: :category_loaded?
  6. def url
  7. full_asset_url(object.image.url)
  8. end
  9. def static_url
  10. full_asset_url(object.image.url(:static))
  11. end
  12. def category
  13. object.category.name
  14. end
  15. def category_loaded?
  16. object.association(:category).loaded? && object.category.present?
  17. end
  18. end