Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/search/sort_options.rb')
-rw-r--r--lib/gitlab/search/sort_options.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/gitlab/search/sort_options.rb b/lib/gitlab/search/sort_options.rb
new file mode 100644
index 00000000000..3395c34d171
--- /dev/null
+++ b/lib/gitlab/search/sort_options.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Search
+ module SortOptions
+ def sort_and_direction(order_by, sort)
+ # Due to different uses of sort param in web vs. API requests we prefer
+ # order_by when present
+ case [order_by, sort]
+ when %w[created_at asc], [nil, 'created_asc']
+ :created_at_asc
+ when %w[created_at desc], [nil, 'created_desc']
+ :created_at_desc
+ else
+ :unknown
+ end
+ end
+ module_function :sort_and_direction # rubocop: disable Style/AccessModifierDeclarations
+ end
+ end
+end