ぼざクリタグ広場 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.
 
 
 
 
 
 

24 lines
589 B

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