clusters_finder.rb 500 Bytes
Newer Older
Matija Čupić's avatar
Matija Čupić committed
1 2 3 4
class ClustersFinder
  def initialize(project, user, scope)
    @project = project
    @user = user
Matija Čupić's avatar
Matija Čupić committed
5
    @scope = scope || :active
Matija Čupić's avatar
Matija Čupić committed
6 7 8
  end

  def execute
Matija Čupić's avatar
Matija Čupić committed
9 10 11 12 13 14
    clusters = project.clusters
    filter_by_scope(clusters)
  end

  private

15 16
  attr_reader :project, :user, :scope

Matija Čupić's avatar
Matija Čupić committed
17
  def filter_by_scope(clusters)
18
    case scope.to_sym
Matija Čupić's avatar
Matija Čupić committed
19 20 21 22 23 24 25
    when :all
      clusters
    when :inactive
      clusters.disabled
    when :active
      clusters.enabled
    else
26
      raise "Invalid scope #{scope}"
Matija Čupić's avatar
Matija Čupić committed
27
    end
Matija Čupić's avatar
Matija Čupić committed
28 29
  end
end