Sha256: 2ed942312077b23c4f0459f980df23b0abdcc20610b93e59a0df70fbe6ef194c

Contents?: true

Size: 1.36 KB

Versions: 31

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

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

      # Serializes a comment
      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

      private

      def root_commentable_url
        @root_commentable_url ||= if resource.root_commentable&.respond_to?(:polymorphic_resource_url)
                                    resource.root_commentable.polymorphic_resource_url
                                  else
                                    ResourceLocatorPresenter.new(resource.root_commentable).url
                                  end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-comments-0.26.8 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.26.7 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.26.5 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.26.4 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.26.3 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.26.2 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.26.1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.26.0 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.26.0.rc2 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.26.0.rc1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.25.2 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.25.1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.25.0 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.25.0.rc4 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.25.0.rc3 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.25.0.rc2 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.25.0.rc1 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.24.3 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.23.6 lib/decidim/comments/comment_serializer.rb
decidim-comments-0.24.2 lib/decidim/comments/comment_serializer.rb