gitlab-org--gitlab-foss/app/finders/clusters_finder.rb

30 lines
500 B
Ruby
Raw Normal View History

2017-11-27 07:48:46 -05:00
class ClustersFinder
def initialize(project, user, scope)
@project = project
@user = user
2017-11-28 08:22:29 -05:00
@scope = scope || :active
2017-11-27 07:48:46 -05:00
end
def execute
2017-11-28 08:22:29 -05:00
clusters = project.clusters
filter_by_scope(clusters)
end
private
attr_reader :project, :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