Class: Decidim::Comments::CommentSerializer

Inherits:
Exporters::Serializer show all
Includes:
ResourceHelper, TranslationsHelper
Defined in:
decidim-comments/lib/decidim/comments/comment_serializer.rb

Instance Attribute Summary

Attributes inherited from Exporters::Serializer

#resource

Instance Method Summary collapse

Methods included from TranslationsHelper

empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?

Methods included from TranslatableAttributes

#default_locale?

Methods included from ResourceHelper

#linked_classes_filter_values_for, #linked_classes_for, #resource_locator, #resource_title

Methods inherited from Exporters::Serializer

#event_name, #finalize, #initialize, #run

Constructor Details

This class inherits a constructor from Decidim::Exporters::Serializer

Instance Method Details

#serializeObject

Serializes a comment



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'decidim-comments/lib/decidim/comments/comment_serializer.rb', line 10

def serialize
  {
    id: resource.id,
    created_at: resource.created_at,
    body: resource.body.values.first,
    locale: resource.body.keys.first,
    author: {
      id: resource.author.id,
      name: resource.author.name
    },
    alignment: resource.alignment,
    depth: resource.depth,
    user_group: {
      id: resource.user_group.try(:id),
      name: resource.user_group.try(:name) || empty_translatable
    },
    commentable_id: resource.decidim_commentable_id,
    commentable_type: resource.decidim_commentable_type,
    root_commentable_url:
  }
end