BigW Consortium Gitlab

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

  def execute
9 10 11 12 13 14
    clusters = project.clusters
    filter_by_scope(clusters)
  end

  private

15 16
  attr_reader :project, :user, :scope

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