Sha256: 5f6a294d4050130df8288cabb79470275d3711dbc5e00b99a8398c7363bcb5a3
Contents?: true
Size: 1.23 KB
Versions: 4
Compression:
Stored size: 1.23 KB
Contents
# frozen_string_literal: true module Lcms module Engine class SearchDocumentSerializer < ActiveModel::Serializer self.root = false attributes :id, :model_id, :model_type, :title, :path, :type_name, :teaser, :breadcrumbs, :subject, :grade def path if model_type == 'page' object.permalink else return media_path(object.model_id) if media? return generic_path(object.model_id) if generic? object.slug ? show_with_slug_path(object.slug) : resource_permalink end end def type_name if generic? && object.grade.present? "#{object.grades.to_str} #{object.doc_type.titleize}" else object.doc_type.titleize end end def grade object.grades&.average end private def media? %w(video podcast).include?(object.doc_type) end def generic? %w(text_set quick_reference_guide).include?(object.doc_type) end def document_permalink document = Resource.find(object.model_id).document document_path(document.id) end def resource_permalink resource_path(object.model_id) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems