Class: BaseSerializer

Inherits:
Object
  • Object
show all
Defined in:
app/serializers/base_serializer.rb

Direct Known Subclasses

AccessibilityReportsComparerSerializer, ActsAsTaggableOn::TagSerializer, AnalyticsBuildSerializer, AnalyticsCommitSerializer, AnalyticsGenericSerializer, AnalyticsStageSerializer, AnalyticsSummarySerializer, BoardSerializer, BuildSerializer, BuildTraceSerializer, Ci::DagPipelineSerializer, Ci::DailyBuildGroupReportResultSerializer, Ci::GroupVariableSerializer, Ci::InstanceVariableSerializer, Ci::Lint::ResultSerializer, Ci::VariableSerializer, ClusterSerializer, ContainerRepositoriesSerializer, ContainerTagsSerializer, CurrentBoardSerializer, DeployKeySerializer, DeploymentSerializer, DiffLineSerializer, DiffsMetadataSerializer, DiffsSerializer, DiscussionSerializer, DraftNoteSerializer, EnvironmentSerializer, EnvironmentStatusSerializer, ErrorTracking::DetailedErrorSerializer, ErrorTracking::ErrorEventSerializer, ErrorTracking::ErrorSerializer, ErrorTracking::ProjectSerializer, Evidences::EvidenceSerializer, Evidences::ReleaseSerializer, ForkNamespaceSerializer, GroupAnalyticsStageSerializer, GroupChildSerializer, GroupDeployKeySerializer, GroupGroupLinkSerializer, GroupSerializer, Import::ProviderRepoSerializer, IssueSerializer, LabelSerializer, LfsFileLockSerializer, LinkedProjectIssueSerializer, MergeRequestCreateSerializer, MergeRequestSerializer, MoveToProjectSerializer, NamespaceSerializer, PaginatedDiffSerializer, PipelineSerializer, ProjectMirrorSerializer, ProjectNoteSerializer, ProjectSerializer, Projects::Serverless::ServiceSerializer, PrometheusAlertSerializer, PrometheusMetricSerializer, ReleaseSerializer, ReviewAppSetupSerializer, RouteSerializer, ServiceEventSerializer, ServiceFieldSerializer, StageSerializer, SuggestionSerializer, TestReportSerializer, TestReportSummarySerializer, TestReportsComparerSerializer, TestSuiteSerializer, UserSerializer, WebIdeTerminalSerializer

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ BaseSerializer

Returns a new instance of BaseSerializer.


6
7
8
9
# File 'app/serializers/base_serializer.rb', line 6

def initialize(params = {})
  @params = params
  @request = EntityRequest.new(params)
end

Class Attribute Details

.entity_classObject (readonly)

Returns the value of attribute entity_class


20
21
22
# File 'app/serializers/base_serializer.rb', line 20

def entity_class
  @entity_class
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params


4
5
6
# File 'app/serializers/base_serializer.rb', line 4

def params
  @params
end

Class Method Details

.entity(entity_class) ⇒ Object


22
23
24
# File 'app/serializers/base_serializer.rb', line 22

def entity(entity_class)
  @entity_class ||= entity_class
end

Instance Method Details

#represent(resource, opts = {}, entity_class = nil) ⇒ Object


11
12
13
14
15
16
17
# File 'app/serializers/base_serializer.rb', line 11

def represent(resource, opts = {}, entity_class = nil)
  entity_class ||= self.class.entity_class

  entity_class
    .represent(resource, opts.merge(request: @request))
    .as_json
end