debian-mirror-gitlab/app/finders/ci/pipeline_schedules_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
883 B
Ruby
Raw Permalink Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
module Ci
class PipelineSchedulesFinder
attr_reader :project, :pipeline_schedules
def initialize(project)
@project = project
@pipeline_schedules = project.pipeline_schedules
end
2023-04-23 21:23:45 +05:30
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)
2020-04-08 14:13:33 +05:30
end
2023-04-23 21:23:45 +05:30
# rubocop:enable CodeReuse/ActiveRecord
2020-04-08 14:13:33 +05:30
end
end