ぼざクリタグ広場 https://hub.nizika.monster
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.
 
 
 
 
 
 

25 lines
653 B

  1. # frozen_string_literal: true
  2. module MaterialRepr
  3. BASE = { only: [:id, :url, :created_at, :updated_at],
  4. methods: [:content_type],
  5. include: { tag: TagRepr::BASE,
  6. created_by_user: UserRepr::BASE,
  7. updated_by_user: UserRepr::BASE } }.freeze
  8. module_function
  9. def base material, host:
  10. material.as_json(BASE).merge(
  11. file: if material.file.attached?
  12. Rails.application.routes.url_helpers.rails_storage_proxy_url(
  13. material.file, host:)
  14. end)
  15. end
  16. def many materials, host:
  17. materials.map { |m| base(m, host) }
  18. end
  19. end