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