Class: Lcms::Engine::ResourceSerializer

Inherits:
ActiveModel::Serializer
  • Object
show all
Includes:
ResourceHelper
Defined in:
app/serializers/lcms/engine/resource_serializer.rb

Overview

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)

Instance Method Summary collapse

Methods included from ResourceHelper

#back_to_resource_path, #copyrights_text, #download_per_category_limit, #prerequisites_standards, #resource_breadcrumbs_with_links, #show_resource_path, #type_name

Instance Method Details



14
15
16
# File 'app/serializers/lcms/engine/resource_serializer.rb', line 14

def breadcrumb_title
  Breadcrumbs.new(object).title
end

#gradeObject



18
19
20
# File 'app/serializers/lcms/engine/resource_serializer.rb', line 18

def grade
  object.grades.average
end

#is_assessmentObject

rubocop:disable Naming/PredicateName



22
23
24
# File 'app/serializers/lcms/engine/resource_serializer.rb', line 22

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

#is_foundationalObject

rubocop:disable Naming/PredicateName



26
27
28
# File 'app/serializers/lcms/engine/resource_serializer.rb', line 26

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

#is_oprObject

rubocop:disable Naming/PredicateName



30
31
32
# File 'app/serializers/lcms/engine/resource_serializer.rb', line 30

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

#is_prerequisiteObject

rubocop:disable Naming/PredicateName



34
35
36
# File 'app/serializers/lcms/engine/resource_serializer.rb', line 34

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

#pathObject



38
39
40
41
42
# File 'app/serializers/lcms/engine/resource_serializer.rb', line 38

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

  show_resource_path(object)
end

#typeObject



44
45
46
# File 'app/serializers/lcms/engine/resource_serializer.rb', line 44

def type
  object.curriculum_type
end