2018-09-11 15:08:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-27 07:48:46 -05:00
|
|
|
class ClustersFinder
|
2018-10-18 21:42:30 -04:00
|
|
|
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
|
2018-10-18 21:42:30 -04:00
|
|
|
clusters = clusterable.clusters
|
2017-11-28 08:22:29 -05:00
|
|
|
filter_by_scope(clusters)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-10-18 21:42:30 -04:00
|
|
|
attr_reader :clusterable, :user, :scope
|
2017-11-28 08:36:12 -05:00
|
|
|
|
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
|