Sha256: 0b89af091e80d2b70a714b10070a042dc22ff7c24d7cc92627233a985423b1b7

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Lcms
  module Engine
    # This is a subset of the previous ResourceSerializer, meant to be used on listings
    # like find_lessons and search cards. We use this instead the full version (ResourceDetailsSerializer)
    # to avoid expensive queries on data we don't need (like downloads, and related)
    class ResourceSerializer < ActiveModel::Serializer
      include ResourceHelper

      self.root = false

      attributes :breadcrumb_title, :grade, :id, :is_assessment, :is_foundational, :is_opr, :is_prerequisite, :path,
                 :short_title, :subject, :teaser, :time_to_teach, :title, :type

      def breadcrumb_title
        Breadcrumbs.new(object).title
      end

      def grade
        object.grades.average
      end

      def is_assessment # rubocop:disable Naming/PredicateName
        object&.assessment? || short_title&.index('assessment').present?
      end

      def is_foundational # rubocop:disable Naming/PredicateName
        object.document&.foundational?
      end

      def is_opr # rubocop:disable Naming/PredicateName
        object.opr?
      end

      def is_prerequisite # rubocop:disable Naming/PredicateName
        object.prerequisite?
      end

      def path
        return document_path(object.document) if object.document? && !object.assessment?

        show_resource_path(object)
      end

      def type
        object.curriculum_type
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lcms-engine-0.1.4 app/serializers/lcms/engine/resource_serializer.rb
lcms-engine-0.1.3 app/serializers/lcms/engine/resource_serializer.rb
lcms-engine-0.1.2 app/serializers/lcms/engine/resource_serializer.rb
lcms-engine-0.1.0 app/serializers/lcms/engine/resource_serializer.rb