Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
ca538899
Commit
ca538899
authored
Sep 04, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a `WithPagination` concern to reuse across serializers
parent
063b5312
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
34 deletions
+27
-34
app/serializers/concerns/with_pagination.rb
app/serializers/concerns/with_pagination.rb
+20
-0
app/serializers/environment_serializer.rb
app/serializers/environment_serializer.rb
+2
-10
app/serializers/group_serializer.rb
app/serializers/group_serializer.rb
+2
-16
app/serializers/pipeline_serializer.rb
app/serializers/pipeline_serializer.rb
+2
-8
config/application.rb
config/application.rb
+1
-0
No files found.
app/serializers/concerns/with_pagination.rb
0 → 100644
View file @
ca538899
module
WithPagination
def
with_pagination
(
request
,
response
)
tap
{
@paginator
=
Gitlab
::
Serializer
::
Pagination
.
new
(
request
,
response
)
}
end
def
paginated?
@paginator
.
present?
end
# super is `BaseSerializer#represent` here.
#
# we shouldn't try to paginate single resources
def
represent
(
resource
,
opts
=
{})
if
paginated?
&&
resource
.
respond_to?
(
:page
)
super
(
@paginator
.
paginate
(
resource
),
opts
)
else
super
(
resource
,
opts
)
end
end
end
app/serializers/environment_serializer.rb
View file @
ca538899
class
EnvironmentSerializer
<
BaseSerializer
class
EnvironmentSerializer
<
BaseSerializer
include
WithPagination
Item
=
Struct
.
new
(
:name
,
:size
,
:latest
)
Item
=
Struct
.
new
(
:name
,
:size
,
:latest
)
entity
EnvironmentEntity
entity
EnvironmentEntity
...
@@ -7,18 +9,10 @@ class EnvironmentSerializer < BaseSerializer
...
@@ -7,18 +9,10 @@ class EnvironmentSerializer < BaseSerializer
tap
{
@itemize
=
true
}
tap
{
@itemize
=
true
}
end
end
def
with_pagination
(
request
,
response
)
tap
{
@paginator
=
Gitlab
::
Serializer
::
Pagination
.
new
(
request
,
response
)
}
end
def
itemized?
def
itemized?
@itemize
@itemize
end
end
def
paginated?
@paginator
.
present?
end
def
represent
(
resource
,
opts
=
{})
def
represent
(
resource
,
opts
=
{})
if
itemized?
if
itemized?
itemize
(
resource
).
map
do
|
item
|
itemize
(
resource
).
map
do
|
item
|
...
@@ -27,8 +21,6 @@ class EnvironmentSerializer < BaseSerializer
...
@@ -27,8 +21,6 @@ class EnvironmentSerializer < BaseSerializer
latest:
super
(
item
.
latest
,
opts
)
}
latest:
super
(
item
.
latest
,
opts
)
}
end
end
else
else
resource
=
@paginator
.
paginate
(
resource
)
if
paginated?
super
(
resource
,
opts
)
super
(
resource
,
opts
)
end
end
end
end
...
...
app/serializers/group_serializer.rb
View file @
ca538899
class
GroupSerializer
<
BaseSerializer
class
GroupSerializer
<
BaseSerializer
entity
GroupEntity
include
WithPagination
def
with_pagination
(
request
,
response
)
tap
{
@paginator
=
Gitlab
::
Serializer
::
Pagination
.
new
(
request
,
response
)
}
end
def
paginated?
entity
GroupEntity
@paginator
.
present?
end
def
represent
(
resource
,
opts
=
{})
if
paginated?
super
(
@paginator
.
paginate
(
resource
),
opts
)
else
super
(
resource
,
opts
)
end
end
end
end
app/serializers/pipeline_serializer.rb
View file @
ca538899
class
PipelineSerializer
<
BaseSerializer
class
PipelineSerializer
<
BaseSerializer
include
WithPagination
InvalidResourceError
=
Class
.
new
(
StandardError
)
InvalidResourceError
=
Class
.
new
(
StandardError
)
entity
PipelineDetailsEntity
entity
PipelineDetailsEntity
def
with_pagination
(
request
,
response
)
tap
{
@paginator
=
Gitlab
::
Serializer
::
Pagination
.
new
(
request
,
response
)
}
end
def
paginated?
@paginator
.
present?
end
def
represent
(
resource
,
opts
=
{})
def
represent
(
resource
,
opts
=
{})
if
resource
.
is_a?
(
ActiveRecord
::
Relation
)
if
resource
.
is_a?
(
ActiveRecord
::
Relation
)
...
...
config/application.rb
View file @
ca538899
...
@@ -29,6 +29,7 @@ module Gitlab
...
@@ -29,6 +29,7 @@ module Gitlab
#{
config
.
root
}
/app/models/project_services
#{
config
.
root
}
/app/models/project_services
#{
config
.
root
}
/app/workers/concerns
#{
config
.
root
}
/app/workers/concerns
#{
config
.
root
}
/app/services/concerns
#{
config
.
root
}
/app/services/concerns
#{
config
.
root
}
/app/serializers/concerns
#{
config
.
root
}
/app/finders/concerns]
)
#{
config
.
root
}
/app/finders/concerns]
)
config
.
generators
.
templates
.
push
(
"
#{
config
.
root
}
/generator_templates"
)
config
.
generators
.
templates
.
push
(
"
#{
config
.
root
}
/generator_templates"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment