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

pipeline_schedules_finder.rb « ci « finders « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5ee65a02c839ba13a6d2c1e5fe955e4769e092f (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
# frozen_string_literal: true

module Ci
  class PipelineSchedulesFinder
    attr_reader :project, :pipeline_schedules

    def initialize(project)
      @project = project
      @pipeline_schedules = project.pipeline_schedules
    end

    def execute(scope: nil, ids: nil)
      items = pipeline_schedules
      items = by_ids(items, ids)
      items = by_scope(items, scope)

      sort_items(items)
    end

    private

    def by_ids(items, ids)
      if ids.present?
        items.id_in(ids)
      else
        items
      end
    end

    def by_scope(items, scope)
      case scope
      when 'active'
        items.active
      when 'inactive'
        items.inactive
      else
        items
      end
    end

    # rubocop:disable CodeReuse/ActiveRecord
    def sort_items(items)
      items.order(id: :desc)
    end
    # rubocop:enable CodeReuse/ActiveRecord
  end
end