summaryrefslogtreecommitdiff
path: root/app/finders/packages/debian/distributions_finder.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
committerRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
commit6438df3a1e0fb944485cebf07976160184697d72 (patch)
tree00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /app/finders/packages/debian/distributions_finder.rb
parent42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff)
downloadgitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'app/finders/packages/debian/distributions_finder.rb')
-rw-r--r--app/finders/packages/debian/distributions_finder.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/app/finders/packages/debian/distributions_finder.rb b/app/finders/packages/debian/distributions_finder.rb
new file mode 100644
index 00000000000..e64b6bdfec1
--- /dev/null
+++ b/app/finders/packages/debian/distributions_finder.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+module Packages
+ module Debian
+ class DistributionsFinder
+ def initialize(container, params = {})
+ @container, @params = container, params
+ end
+
+ def execute
+ collection = relation.with_container(container)
+ collection = by_codename(collection)
+ collection = by_suite(collection)
+ collection = by_codename_or_suite(collection)
+ collection
+ end
+
+ private
+
+ attr_reader :container, :params
+
+ def relation
+ case container
+ when Project
+ Packages::Debian::ProjectDistribution
+ when Group
+ Packages::Debian::GroupDistribution
+ else
+ raise ArgumentError, "Unexpected container type of '#{container.class}'"
+ end
+ end
+
+ def by_codename(collection)
+ return collection unless params[:codename].present?
+
+ collection.with_codename(params[:codename])
+ end
+
+ def by_suite(collection)
+ return collection unless params[:suite].present?
+
+ collection.with_suite(params[:suite])
+ end
+
+ def by_codename_or_suite(collection)
+ return collection unless params[:codename_or_suite].present?
+
+ collection.with_codename_or_suite(params[:codename_or_suite])
+ end
+ end
+ end
+end