debian-mirror-gitlab/app/finders/clusters_finder.rb

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

32 lines
551 B
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
class ClustersFinder
2018-12-13 13:39:08 +05:30
def initialize(clusterable, user, scope)
@clusterable = clusterable
2018-03-17 18:26:18 +05:30
@user = user
@scope = scope || :active
end
def execute
2018-12-13 13:39:08 +05:30
clusters = clusterable.clusters
2018-03-17 18:26:18 +05:30
filter_by_scope(clusters)
end
private
2018-12-13 13:39:08 +05:30
attr_reader :clusterable, :user, :scope
2018-03-17 18:26:18 +05:30
def filter_by_scope(clusters)
case scope.to_sym
when :all
clusters
when :inactive
clusters.disabled
when :active
clusters.enabled
else
raise "Invalid scope #{scope}"
end
end
end