inline_renderer.rb 781 B

123456789101112131415161718192021222324252627282930313233
  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. else
  15. return
  16. end
  17. serializable_resource = ActiveModelSerializers::SerializableResource.new(@object, serializer: serializer, scope: current_user, scope_name: :current_user)
  18. serializable_resource.as_json
  19. end
  20. def self.render(object, current_account, template)
  21. new(object, current_account, template).render
  22. end
  23. private
  24. def current_user
  25. @current_account&.user
  26. end
  27. end