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.

41 lines
1.0 KiB

  1. # frozen_string_literal: true
  2. class InlineRenderer
  3. def initialize(object, current_account, template)
  4. @object = object
  5. @current_account = current_account
  6. @template = template
  7. end
  8. def render
  9. case @template
  10. when :status
  11. serializer = REST::StatusSerializer
  12. when :notification
  13. serializer = REST::NotificationSerializer
  14. when :conversation
  15. serializer = REST::ConversationSerializer
  16. when :announcement
  17. serializer = REST::AnnouncementSerializer
  18. when :reaction
  19. serializer = REST::ReactionSerializer
  20. when :encrypted_message
  21. serializer = REST::EncryptedMessageSerializer
  22. else
  23. return
  24. end
  25. serializable_resource = ActiveModelSerializers::SerializableResource.new(@object, serializer: serializer, scope: current_user, scope_name: :current_user)
  26. serializable_resource.as_json
  27. end
  28. def self.render(object, current_account, template)
  29. new(object, current_account, template).render
  30. end
  31. private
  32. def current_user
  33. @current_account&.user
  34. end
  35. end