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
Tatuya Kamada
gitlab-ce
Commits
030adf12
Commit
030adf12
authored
Feb 02, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Encapsulate reused pagination component in a class
parent
ac060701
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
28 deletions
+42
-28
app/serializers/environment_serializer.rb
app/serializers/environment_serializer.rb
+9
-1
app/serializers/paginator.rb
app/serializers/paginator.rb
+23
-0
app/serializers/pipeline_serializer.rb
app/serializers/pipeline_serializer.rb
+10
-27
No files found.
app/serializers/environment_serializer.rb
View file @
030adf12
...
...
@@ -7,12 +7,20 @@ class EnvironmentSerializer < BaseSerializer
tap
{
@itemize
=
true
}
end
def
with_pagination
(
request
,
response
)
tap
{
@paginator
=
Paginator
.
new
(
request
,
response
)
}
end
def
itemized?
@itemize
end
def
paginated?
defined?
(
@paginator
)
end
def
represent
(
resource
,
opts
=
{})
# resource =
paginate(resource) if paginated?
resource
=
@paginator
.
paginate
(
resource
)
if
paginated?
if
itemized?
itemize
(
resource
).
map
do
|
item
|
...
...
app/serializers/paginator.rb
0 → 100644
View file @
030adf12
class
Paginator
include
API
::
Helpers
::
Pagination
def
initialize
(
request
,
response
)
@request
=
request
@response
=
response
end
private
# Methods needed by `API::Helpers::Pagination`
#
attr_reader
:request
def
params
@request
.
query_parameters
end
def
header
(
header
,
value
)
@response
.
headers
[
header
]
=
value
end
end
app/serializers/pipeline_serializer.rb
View file @
030adf12
class
PipelineSerializer
<
BaseSerializer
class
InvalidResourceError
<
StandardError
;
end
include
API
::
Helpers
::
Pagination
Struct
.
new
(
'Pagination'
,
:request
,
:response
)
entity
PipelineEntity
def
represent
(
resource
,
opts
=
{})
if
paginated?
raise
InvalidResourceError
unless
resource
.
respond_to?
(
:page
)
super
(
paginate
(
resource
.
includes
(
project: :namespace
)),
opts
)
else
super
(
resource
,
opts
)
end
def
with_pagination
(
request
,
response
)
tap
{
@paginator
=
Paginator
.
new
(
request
,
response
)
}
end
def
paginated?
defined?
(
@paginat
ion
)
defined?
(
@paginat
or
)
end
def
with_pagination
(
request
,
response
)
tap
{
@pagination
=
Struct
::
Pagination
.
new
(
request
,
response
)
}
end
private
# Methods needed by `API::Helpers::Pagination`
#
def
params
@pagination
.
request
.
query_parameters
end
def
represent
(
resource
,
opts
=
{})
if
paginated?
raise
InvalidResourceError
unless
resource
.
respond_to?
(
:page
)
def
request
@pagination
.
request
resource
=
resource
.
includes
(
project: :namespace
)
super
(
@paginator
.
paginate
(
resource
),
opts
)
else
super
(
resource
,
opts
)
end
def
header
(
header
,
value
)
@pagination
.
response
.
headers
[
header
]
=
value
end
end
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