Class: Decidim::Comments::CommentSerializer

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

Instance Method Summary collapse

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 '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: root_commentable_url
  }
end