Class: Lcms::Engine::DocumentMaterialSerializer
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- Lcms::Engine::DocumentMaterialSerializer
- Defined in:
- app/serializers/lcms/engine/document_material_serializer.rb
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(document, materials) ⇒ DocumentMaterialSerializer
constructor
A new instance of DocumentMaterialSerializer.
Constructor Details
#initialize(document, materials) ⇒ DocumentMaterialSerializer
Returns a new instance of DocumentMaterialSerializer.
8 9 10 11 12 |
# File 'app/serializers/lcms/engine/document_material_serializer.rb', line 8 def initialize(document, materials) super(document) @document = document @materials = materials end |
Instance Method Details
#data ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/serializers/lcms/engine/document_material_serializer.rb', line 14 def data ordered_ids = @document.ordered_material_ids anchors = @document.materials_anchors @materials .sort_by { |m| ordered_ids.index(m.id) } .map do |material| MaterialSerializer.new( DocumentGenerator.material_presenter.new material, document: @document, anchors: anchors[material.id] || [] ).as_json end end |