Sha256: 5c68e7a87924808fbc6674b1bf919d37b0b248686322eb00eb232992d35f7065

Contents?: true

Size: 1011 Bytes

Versions: 72

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    class CommentSerializer < Decidim::Exporters::Serializer
      include Decidim::ResourceHelper

      # Serializes a comment
      def serialize
        {
          id: resource.id,
          created_at: resource.created_at,
          body: resource.body,
          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)
          },
          commentable_id: resource.decidim_commentable_id,
          commentable_type: resource.decidim_commentable_type,
          root_commentable_url: root_commentable_url
        }
      end

      private

      def root_commentable_url
        @root_commentable_url ||= Decidim::ResourceLocatorPresenter.new(resource.root_commentable).url
      end
    end
  end
end

Version data entries

72 entries across 72 versions & 2 rubygems

Version Path
decidim-comments-0.16.0 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.15.2 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.15.1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.15.0 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.14.4 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.14.3 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.14.2 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.14.1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.13.1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.12.2 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.13.0 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.12.1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.13.0.pre1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.12.0 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.11.2 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.12.0.pre lib/decidim/comments/comment_serializer.rb
decidim-comments-0.11.1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.11.0.pre1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.10.1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.10.0 lib/decidim/comments/comment_serializer.rb