gitlab-org--gitlab-foss/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

# frozen_string_literal: true
2017-11-27 07:48:46 -05:00
class ClustersFinder
def initialize(clusterable, user, scope)
@clusterable = clusterable
2017-11-27 07:48:46 -05:00
@user = user
2017-11-28 08:22:29 -05:00
@scope = scope || :active
2017-11-27 07:48:46 -05:00
end
def execute
clusters = clusterable.clusters
2017-11-28 08:22:29 -05:00
filter_by_scope(clusters)
end
private
attr_reader :clusterable, :user, :scope
2017-11-28 08:22:29 -05:00
def filter_by_scope(clusters)
case scope.to_sym
2017-11-28 08:22:29 -05:00
when :all
clusters
when :inactive
clusters.disabled
when :active
clusters.enabled
else
raise "Invalid scope #{scope}"
2017-11-28 08:22:29 -05:00
end
2017-11-27 07:48:46 -05:00
end
end