From 6438df3a1e0fb944485cebf07976160184697d72 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 20 Jan 2021 13:34:23 -0600 Subject: Add latest changes from gitlab-org/gitlab@13-8-stable-ee --- .../packages/debian/distributions_finder.rb | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/finders/packages/debian/distributions_finder.rb (limited to 'app/finders/packages/debian/distributions_finder.rb') 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 -- cgit v1.2.1