summaryrefslogtreecommitdiff
path: root/lib/api/helpers/pagination.rb
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2019-02-28 19:57:34 +0100
committerToon Claes <toon@gitlab.com>2019-02-28 19:57:34 +0100
commit62d7990b9bb30cf33ed87017c5c633d1cccc75c2 (patch)
treec3e1b69c58a412ba1c6f50a0337a23d9f9d6e1a4 /lib/api/helpers/pagination.rb
parentf6453eca992a9c142268e78ac782cef98110d183 (diff)
downloadgitlab-ce-tc-standard-gem.tar.gz
Ran standardrb --fix on the whole codebasetc-standard-gem
Inspired by https://twitter.com/searls/status/1101137953743613952 I decided to try https://github.com/testdouble/standard on our codebase. It's opinionated, but at least it's a _standard_.
Diffstat (limited to 'lib/api/helpers/pagination.rb')
-rw-r--r--lib/api/helpers/pagination.rb62
1 files changed, 31 insertions, 31 deletions
diff --git a/lib/api/helpers/pagination.rb b/lib/api/helpers/pagination.rb
index d00e61678b5..a125020d6eb 100644
--- a/lib/api/helpers/pagination.rb
+++ b/lib/api/helpers/pagination.rb
@@ -4,11 +4,11 @@ module API
module Helpers
module Pagination
def paginate(relation)
- strategy = if params[:pagination] == 'keyset' && Feature.enabled?('api_keyset_pagination')
- KeysetPaginationStrategy
- else
- DefaultPaginationStrategy
- end
+ strategy = if params[:pagination] == "keyset" && Feature.enabled?("api_keyset_pagination")
+ KeysetPaginationStrategy
+ else
+ DefaultPaginationStrategy
+ end
strategy.new(self).paginate(relation)
end
@@ -66,12 +66,12 @@ module API
# Sort direction (`:asc` or `:desc`)
def sort
@sort ||= if order_by_primary_key?
- # Default order is by id DESC
- :desc
- else
- # API defaults to DESC order if param `sort` not present
- request_context.params[:sort]&.to_sym || :desc
- end
+ # Default order is by id DESC
+ :desc
+ else
+ # API defaults to DESC order if param `sort` not present
+ request_context.params[:sort]&.to_sym || :desc
+ end
end
# Do we only sort by primary key?
@@ -100,9 +100,9 @@ module API
# All values present in request parameters that correspond to #keys.
def values
- @values ||= keys.map do |key|
+ @values ||= keys.map { |key|
request_context.params["ks_prev_#{key}".to_sym]
- end
+ }
end
# All keys relevant to pagination.
@@ -151,30 +151,30 @@ module API
return nil if fields.empty?
- placeholder = fields.map { '?' }
+ placeholder = fields.map { "?" }
comp = if pagination.sort_ascending?
- '>'
- else
- '<'
- end
+ ">"
+ else
+ "<"
+ end
[
# Row value comparison:
# (A, B) < (a, b) <=> (A < a) OR (A = a AND B < b)
# <=> A <= a AND ((A < a) OR (A = a AND B < b))
- "(#{fields.keys.join(',')}) #{comp} (#{placeholder.join(',')})",
- *fields.values
+ "(#{fields.keys.join(",")}) #{comp} (#{placeholder.join(",")})",
+ *fields.values,
]
end
def add_default_pagination_headers
- header 'X-Per-Page', per_page.to_s
+ header "X-Per-Page", per_page.to_s
end
def add_navigation_links(next_page_params)
- header 'X-Next-Page', page_href(next_page_params)
- header 'Link', link_for('next', next_page_params)
+ header "X-Next-Page", page_href(next_page_params)
+ header "Link", link_for("next", next_page_params)
end
def link_for(rel, next_page_params)
@@ -220,16 +220,16 @@ module API
end
def add_pagination_headers(paginated_data)
- header 'X-Per-Page', paginated_data.limit_value.to_s
- header 'X-Page', paginated_data.current_page.to_s
- header 'X-Next-Page', paginated_data.next_page.to_s
- header 'X-Prev-Page', paginated_data.prev_page.to_s
- header 'Link', pagination_links(paginated_data)
+ header "X-Per-Page", paginated_data.limit_value.to_s
+ header "X-Page", paginated_data.current_page.to_s
+ header "X-Next-Page", paginated_data.next_page.to_s
+ header "X-Prev-Page", paginated_data.prev_page.to_s
+ header "Link", pagination_links(paginated_data)
return if data_without_counts?(paginated_data)
- header 'X-Total', paginated_data.total_count.to_s
- header 'X-Total-Pages', total_pages(paginated_data).to_s
+ header "X-Total", paginated_data.total_count.to_s
+ header "X-Total-Pages", total_pages(paginated_data).to_s
end
def pagination_links(paginated_data)
@@ -239,7 +239,7 @@ module API
links << %(<#{page_href(page: 1)}>; rel="first")
links << %(<#{page_href(page: total_pages(paginated_data))}>; rel="last") unless data_without_counts?(paginated_data)
- end.join(', ')
+ end.join(", ")
end
def total_pages(paginated_data)