|
- # frozen_string_literal: true
-
-
- module MaterialRepr
- BASE = { methods: [:content_type],
- include: { created_by_user: UserRepr::BASE,
- updated_by_user: UserRepr::BASE } }.freeze
-
- module_function
-
- def base(material)
- material.as_json(BASE).merge(
- file: if material.file.attached?
- Rails.application.routes.url_helpers.rails_storage_proxy_url(
- material.file, only_path: false)
- end,
- tag: TagRepr.base(material.tag))
- end
-
- def many(materials)
- materials.map { |m| base(m) }
- end
- end
|