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
|
|
|
|
|
2017-11-28 08:36:12 -05:00
|
|
|
attr_reader :project, :user, :scope
|
|
|
|
|
2017-11-28 08:22:29 -05:00
|
|
|
def filter_by_scope(clusters)
|
2017-11-28 08:36:12 -05:00
|
|
|
case scope.to_sym
|
2017-11-28 08:22:29 -05:00
|
|
|
when :all
|
|
|
|
clusters
|
|
|
|
when :inactive
|
|
|
|
clusters.disabled
|
|
|
|
when :active
|
|
|
|
clusters.enabled
|
|
|
|
else
|
2017-11-28 08:36:12 -05:00
|
|
|
raise "Invalid scope #{scope}"
|
2017-11-28 08:22:29 -05:00
|
|
|
end
|
2017-11-27 07:48:46 -05:00
|
|
|
end
|
|
|
|
end
|