summaryrefslogtreecommitdiff
path: root/app/services/packages/debian/destroy_distribution_service.rb
blob: bef1127feced2aed597e49c5731bd27a47f44990 (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
# frozen_string_literal: true

module Packages
  module Debian
    class DestroyDistributionService
      def initialize(distribution)
        @distribution = distribution
      end

      def execute
        destroy_distribution
      end

      private

      def destroy_distribution
        if @distribution.destroy
          success
        else
          error("Unable to destroy Debian #{@distribution.model_name.human.downcase}")
        end
      end

      def success
        ServiceResponse.success
      end

      def error(message)
        ServiceResponse.error(message: message, payload: { distribution: @distribution })
      end
    end
  end
end