Commit dce26700 authored by gfyoung's avatar gfyoung

Enable frozen string in app/serializers/**/*.rb

Partially addresses #47424.
parent e23b966d
# frozen_string_literal: true
class AnalyticsBuildEntity < Grape::Entity class AnalyticsBuildEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
include EntityDateHelper include EntityDateHelper
......
# frozen_string_literal: true
class AnalyticsBuildSerializer < BaseSerializer class AnalyticsBuildSerializer < BaseSerializer
entity AnalyticsBuildEntity entity AnalyticsBuildEntity
end end
# frozen_string_literal: true
class AnalyticsCommitEntity < CommitEntity class AnalyticsCommitEntity < CommitEntity
include EntityDateHelper include EntityDateHelper
......
# frozen_string_literal: true
class AnalyticsCommitSerializer < BaseSerializer class AnalyticsCommitSerializer < BaseSerializer
entity AnalyticsCommitEntity entity AnalyticsCommitEntity
end end
# frozen_string_literal: true
class AnalyticsGenericSerializer < BaseSerializer class AnalyticsGenericSerializer < BaseSerializer
def represent(resource, opts = {}) def represent(resource, opts = {})
resource.symbolize_keys! resource.symbolize_keys!
......
# frozen_string_literal: true
class AnalyticsIssueEntity < Grape::Entity class AnalyticsIssueEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
include EntityDateHelper include EntityDateHelper
......
# frozen_string_literal: true
class AnalyticsIssueSerializer < AnalyticsGenericSerializer class AnalyticsIssueSerializer < AnalyticsGenericSerializer
entity AnalyticsIssueEntity entity AnalyticsIssueEntity
end end
# frozen_string_literal: true
class AnalyticsMergeRequestEntity < AnalyticsIssueEntity class AnalyticsMergeRequestEntity < AnalyticsIssueEntity
expose :state expose :state
......
# frozen_string_literal: true
class AnalyticsMergeRequestSerializer < AnalyticsGenericSerializer class AnalyticsMergeRequestSerializer < AnalyticsGenericSerializer
entity AnalyticsMergeRequestEntity entity AnalyticsMergeRequestEntity
end end
# frozen_string_literal: true
class AnalyticsStageEntity < Grape::Entity class AnalyticsStageEntity < Grape::Entity
include EntityDateHelper include EntityDateHelper
......
# frozen_string_literal: true
class AnalyticsStageSerializer < BaseSerializer class AnalyticsStageSerializer < BaseSerializer
entity AnalyticsStageEntity entity AnalyticsStageEntity
end end
# frozen_string_literal: true
class AnalyticsSummaryEntity < Grape::Entity class AnalyticsSummaryEntity < Grape::Entity
expose :value, safe: true expose :value, safe: true
expose :title expose :title
......
# frozen_string_literal: true
class AnalyticsSummarySerializer < BaseSerializer class AnalyticsSummarySerializer < BaseSerializer
entity AnalyticsSummaryEntity entity AnalyticsSummaryEntity
end end
# frozen_string_literal: true
class AwardEmojiEntity < Grape::Entity class AwardEmojiEntity < Grape::Entity
expose :name expose :name
expose :user, using: API::Entities::UserSafe expose :user, using: API::Entities::UserSafe
......
# frozen_string_literal: true
class BaseSerializer class BaseSerializer
attr_reader :params attr_reader :params
......
# frozen_string_literal: true
class BlobEntity < Grape::Entity class BlobEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class BuildActionEntity < Grape::Entity class BuildActionEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class BuildArtifactEntity < Grape::Entity class BuildArtifactEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class BuildDetailsEntity < JobEntity class BuildDetailsEntity < JobEntity
expose :coverage, :erased_at, :duration expose :coverage, :erased_at, :duration
expose :tag_list, as: :tags expose :tag_list, as: :tags
......
# frozen_string_literal: true
class BuildMetadataEntity < Grape::Entity class BuildMetadataEntity < Grape::Entity
expose :timeout_human_readable expose :timeout_human_readable
expose :timeout_source do |metadata| expose :timeout_source do |metadata|
......
# frozen_string_literal: true
class BuildSerializer < BaseSerializer class BuildSerializer < BaseSerializer
entity JobEntity entity JobEntity
......
# frozen_string_literal: true
class ClusterApplicationEntity < Grape::Entity class ClusterApplicationEntity < Grape::Entity
expose :name expose :name
expose :status_name, as: :status expose :status_name, as: :status
......
# frozen_string_literal: true
class ClusterEntity < Grape::Entity class ClusterEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class ClusterSerializer < BaseSerializer class ClusterSerializer < BaseSerializer
entity ClusterEntity entity ClusterEntity
......
# frozen_string_literal: true
class CohortActivityMonthEntity < Grape::Entity class CohortActivityMonthEntity < Grape::Entity
include ActionView::Helpers::NumberHelper include ActionView::Helpers::NumberHelper
......
# frozen_string_literal: true
class CohortEntity < Grape::Entity class CohortEntity < Grape::Entity
include ActionView::Helpers::NumberHelper include ActionView::Helpers::NumberHelper
......
# frozen_string_literal: true
class CohortsEntity < Grape::Entity class CohortsEntity < Grape::Entity
expose :months_included expose :months_included
expose :cohorts, using: CohortEntity expose :cohorts, using: CohortEntity
......
# frozen_string_literal: true
class CohortsSerializer < AnalyticsGenericSerializer class CohortsSerializer < AnalyticsGenericSerializer
entity CohortsEntity entity CohortsEntity
end end
# frozen_string_literal: true
class CommitEntity < API::Entities::Commit class CommitEntity < API::Entities::Commit
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
module WithPagination module WithPagination
attr_accessor :paginator attr_accessor :paginator
......
# frozen_string_literal: true
class ContainerRepositoriesSerializer < BaseSerializer class ContainerRepositoriesSerializer < BaseSerializer
entity ContainerRepositoryEntity entity ContainerRepositoryEntity
end end
# frozen_string_literal: true
class ContainerRepositoryEntity < Grape::Entity class ContainerRepositoryEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class ContainerTagEntity < Grape::Entity class ContainerTagEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class ContainerTagsSerializer < BaseSerializer class ContainerTagsSerializer < BaseSerializer
entity ContainerTagEntity entity ContainerTagEntity
......
# frozen_string_literal: true
class DeployKeyEntity < Grape::Entity class DeployKeyEntity < Grape::Entity
expose :id expose :id
expose :user_id expose :user_id
......
# frozen_string_literal: true
class DeployKeySerializer < BaseSerializer class DeployKeySerializer < BaseSerializer
entity DeployKeyEntity entity DeployKeyEntity
end end
# frozen_string_literal: true
class DeployKeysProjectEntity < Grape::Entity class DeployKeysProjectEntity < Grape::Entity
expose :can_push expose :can_push
expose :project, using: ProjectEntity expose :project, using: ProjectEntity
......
# frozen_string_literal: true
class DeploymentEntity < Grape::Entity class DeploymentEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class DeploymentSerializer < BaseSerializer class DeploymentSerializer < BaseSerializer
entity DeploymentEntity entity DeploymentEntity
......
# frozen_string_literal: true
class DiffFileEntity < Grape::Entity class DiffFileEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
include BlobHelper include BlobHelper
......
# frozen_string_literal: true
class DiffsEntity < Grape::Entity class DiffsEntity < Grape::Entity
include DiffHelper include DiffHelper
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class DiffsSerializer < BaseSerializer class DiffsSerializer < BaseSerializer
entity DiffsEntity entity DiffsEntity
end end
# frozen_string_literal: true
class DiscussionEntity < Grape::Entity class DiscussionEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
include NotesHelper include NotesHelper
......
# frozen_string_literal: true
class DiscussionSerializer < BaseSerializer class DiscussionSerializer < BaseSerializer
entity DiscussionEntity entity DiscussionEntity
end end
# frozen_string_literal: true
module EntityDateHelper module EntityDateHelper
include ActionView::Helpers::DateHelper include ActionView::Helpers::DateHelper
include ActionView::Helpers::TagHelper include ActionView::Helpers::TagHelper
...@@ -50,15 +52,20 @@ module EntityDateHelper ...@@ -50,15 +52,20 @@ module EntityDateHelper
elsif entity.due_date elsif entity.due_date
is_upcoming = (entity.due_date - Date.today).to_i > 0 is_upcoming = (entity.due_date - Date.today).to_i > 0
time_ago = time_ago_in_words(entity.due_date) time_ago = time_ago_in_words(entity.due_date)
content = time_ago.gsub(/\d+/) { |match| "<strong>#{match}</strong>" }
content.slice!("about ") # https://gitlab.com/gitlab-org/gitlab-ce/issues/49440
content << " " + (is_upcoming ? _("remaining") : _("ago")) #
content.html_safe # Need to improve the i18n here and do a full translation
# of the string instead of piecewise translations.
content = time_ago
.gsub(/\d+/) { |match| "<strong>#{match}</strong>" }
.remove("about ")
remaining_or_ago = is_upcoming ? _("remaining") : _("ago")
"#{content} #{remaining_or_ago}".html_safe
elsif entity.start_date && entity.start_date.past? elsif entity.start_date && entity.start_date.past?
days = entity.elapsed_days days = entity.elapsed_days
content = content_tag(:strong, days) "#{content_tag(:strong, days)} #{'day'.pluralize(days)} elapsed".html_safe
content << " #{'day'.pluralize(days)} elapsed"
content.html_safe
end end
end end
end end
# frozen_string_literal: true
class EntityRequest class EntityRequest
# We use EntityRequest object to collect parameters and variables # We use EntityRequest object to collect parameters and variables
# from the controller. Because options that are being passed to the entity # from the controller. Because options that are being passed to the entity
......
# frozen_string_literal: true
class EnvironmentEntity < Grape::Entity class EnvironmentEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class EnvironmentSerializer < BaseSerializer class EnvironmentSerializer < BaseSerializer
include WithPagination include WithPagination
......
# frozen_string_literal: true
class GroupChildEntity < Grape::Entity class GroupChildEntity < Grape::Entity
include ActionView::Helpers::NumberHelper include ActionView::Helpers::NumberHelper
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class GroupChildSerializer < BaseSerializer class GroupChildSerializer < BaseSerializer
include WithPagination include WithPagination
......
# frozen_string_literal: true
class GroupEntity < Grape::Entity class GroupEntity < Grape::Entity
include ActionView::Helpers::NumberHelper include ActionView::Helpers::NumberHelper
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class GroupSerializer < BaseSerializer class GroupSerializer < BaseSerializer
include WithPagination include WithPagination
......
# frozen_string_literal: true
class GroupVariableEntity < Grape::Entity class GroupVariableEntity < Grape::Entity
expose :id expose :id
expose :key expose :key
......
# frozen_string_literal: true
class GroupVariableSerializer < BaseSerializer class GroupVariableSerializer < BaseSerializer
entity GroupVariableEntity entity GroupVariableEntity
end end
# frozen_string_literal: true
class IssuableEntity < Grape::Entity class IssuableEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class IssuableSidebarEntity < Grape::Entity class IssuableSidebarEntity < Grape::Entity
include TimeTrackableEntity include TimeTrackableEntity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class IssueEntity < IssuableEntity class IssueEntity < IssuableEntity
include TimeTrackableEntity include TimeTrackableEntity
......
# frozen_string_literal: true
class IssueSerializer < BaseSerializer class IssueSerializer < BaseSerializer
# This overrided method takes care of which entity should be used # This overrided method takes care of which entity should be used
# to serialize the `issue` based on `basic` key in `opts` param. # to serialize the `issue` based on `basic` key in `opts` param.
......
# frozen_string_literal: true
class IssueSidebarEntity < IssuableSidebarEntity class IssueSidebarEntity < IssuableSidebarEntity
expose :assignees, using: API::Entities::UserBasic expose :assignees, using: API::Entities::UserBasic
end end
# frozen_string_literal: true
class JobEntity < Grape::Entity class JobEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class JobGroupEntity < Grape::Entity class JobGroupEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class LabelEntity < Grape::Entity class LabelEntity < Grape::Entity
expose :id, if: ->(label, _) { !label.is_a?(GlobalLabel) } expose :id, if: ->(label, _) { !label.is_a?(GlobalLabel) }
......
# frozen_string_literal: true
class LabelSerializer < BaseSerializer class LabelSerializer < BaseSerializer
entity LabelEntity entity LabelEntity
......
# frozen_string_literal: true
class LfsFileLockEntity < Grape::Entity class LfsFileLockEntity < Grape::Entity
root 'locks', 'lock' root 'locks', 'lock'
......
# frozen_string_literal: true
class LfsFileLockSerializer < BaseSerializer class LfsFileLockSerializer < BaseSerializer
entity LfsFileLockEntity entity LfsFileLockEntity
end end
# frozen_string_literal: true
class MergeRequestBasicEntity < IssuableSidebarEntity class MergeRequestBasicEntity < IssuableSidebarEntity
expose :assignee_id expose :assignee_id
expose :merge_status expose :merge_status
......
# frozen_string_literal: true
class MergeRequestBasicSerializer < BaseSerializer class MergeRequestBasicSerializer < BaseSerializer
entity MergeRequestBasicEntity entity MergeRequestBasicEntity
end end
# frozen_string_literal: true
class MergeRequestCreateEntity < Grape::Entity class MergeRequestCreateEntity < Grape::Entity
expose :iid expose :iid
......
# frozen_string_literal: true
class MergeRequestCreateSerializer < BaseSerializer class MergeRequestCreateSerializer < BaseSerializer
entity MergeRequestCreateEntity entity MergeRequestCreateEntity
end end
# frozen_string_literal: true
class MergeRequestDiffEntity < Grape::Entity class MergeRequestDiffEntity < Grape::Entity
include Gitlab::Routing include Gitlab::Routing
include GitHelper include GitHelper
......
# frozen_string_literal: true
class MergeRequestMetricsEntity < Grape::Entity class MergeRequestMetricsEntity < Grape::Entity
expose :latest_closed_at, as: :closed_at expose :latest_closed_at, as: :closed_at
expose :merged_at expose :merged_at
......
# frozen_string_literal: true
class MergeRequestSerializer < BaseSerializer class MergeRequestSerializer < BaseSerializer
# This overrided method takes care of which entity should be used # This overrided method takes care of which entity should be used
# to serialize the `merge_request` based on `serializer` key in `opts` param. # to serialize the `merge_request` based on `serializer` key in `opts` param.
......
# frozen_string_literal: true
class MergeRequestUserEntity < UserEntity class MergeRequestUserEntity < UserEntity
include RequestAwareEntity include RequestAwareEntity
include BlobHelper include BlobHelper
......
# frozen_string_literal: true
class MergeRequestWidgetEntity < IssuableEntity class MergeRequestWidgetEntity < IssuableEntity
expose :state expose :state
expose :in_progress_merge_commit_sha expose :in_progress_merge_commit_sha
......
# frozen_string_literal: true
class NoteAttachmentEntity < Grape::Entity class NoteAttachmentEntity < Grape::Entity
expose :url expose :url
expose :filename expose :filename
......
# frozen_string_literal: true
class NoteEntity < API::Entities::Note class NoteEntity < API::Entities::Note
include RequestAwareEntity include RequestAwareEntity
include NotesHelper include NotesHelper
......
# frozen_string_literal: true
class NoteUserEntity < UserEntity class NoteUserEntity < UserEntity
unexpose :web_url unexpose :web_url
end end
# frozen_string_literal: true
class PipelineDetailsEntity < PipelineEntity class PipelineDetailsEntity < PipelineEntity
expose :details do expose :details do
expose :ordered_stages, as: :stages, using: StageEntity expose :ordered_stages, as: :stages, using: StageEntity
......
# frozen_string_literal: true
class PipelineEntity < Grape::Entity class PipelineEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class PipelineSerializer < BaseSerializer class PipelineSerializer < BaseSerializer
include WithPagination include WithPagination
entity PipelineDetailsEntity entity PipelineDetailsEntity
......
# frozen_string_literal: true
class ProjectEntity < Grape::Entity class ProjectEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class ProjectMirrorEntity < Grape::Entity class ProjectMirrorEntity < Grape::Entity
expose :id expose :id
......
# frozen_string_literal: true
class ProjectNoteEntity < NoteEntity class ProjectNoteEntity < NoteEntity
expose :human_access do |note| expose :human_access do |note|
note.project.team.human_max_access(note.author_id) note.project.team.human_max_access(note.author_id)
......
# frozen_string_literal: true
class ProjectNoteSerializer < BaseSerializer class ProjectNoteSerializer < BaseSerializer
entity ProjectNoteEntity entity ProjectNoteEntity
end end
# frozen_string_literal: true
class ProjectSerializer < BaseSerializer class ProjectSerializer < BaseSerializer
entity ProjectEntity entity ProjectEntity
end end
# frozen_string_literal: true
module RequestAwareEntity module RequestAwareEntity
extend ActiveSupport::Concern extend ActiveSupport::Concern
......
# frozen_string_literal: true
class RunnerEntity < Grape::Entity class RunnerEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class StageEntity < Grape::Entity class StageEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class StageSerializer < BaseSerializer class StageSerializer < BaseSerializer
include WithPagination include WithPagination
......
# frozen_string_literal: true
class StatusEntity < Grape::Entity class StatusEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class SubmoduleEntity < Grape::Entity class SubmoduleEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
module TimeTrackableEntity module TimeTrackableEntity
extend ActiveSupport::Concern extend ActiveSupport::Concern
extend Grape extend Grape
......
# frozen_string_literal: true
class TreeEntity < Grape::Entity class TreeEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
# TODO: Inherit from TreeEntity, when `Tree` implements `id` and `name` like `Gitlab::Git::Tree`. # TODO: Inherit from TreeEntity, when `Tree` implements `id` and `name` like `Gitlab::Git::Tree`.
class TreeRootEntity < Grape::Entity class TreeRootEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class TreeSerializer < BaseSerializer class TreeSerializer < BaseSerializer
entity TreeRootEntity entity TreeRootEntity
end end
# frozen_string_literal: true
class UserEntity < API::Entities::UserBasic class UserEntity < API::Entities::UserBasic
include RequestAwareEntity include RequestAwareEntity
......
# frozen_string_literal: true
class UserSerializer < BaseSerializer class UserSerializer < BaseSerializer
entity UserEntity entity UserEntity
end end
# frozen_string_literal: true
class VariableEntity < Grape::Entity class VariableEntity < Grape::Entity
expose :id expose :id
expose :key expose :key
......
# frozen_string_literal: true
class VariableSerializer < BaseSerializer class VariableSerializer < BaseSerializer
entity VariableEntity entity VariableEntity
end end
---
title: Enable frozen string in app/serializers/**/*.rb
merge_request: 20726
author: gfyoung
type: performance
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment