summaryrefslogtreecommitdiff
path: root/app/finders/packages/debian/distributions_finder.rb
blob: e64b6bdfec118294b08016d3bc73dc8637031461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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