summaryrefslogtreecommitdiff
path: root/app/finders/clusters_finder.rb
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2017-11-28 14:22:29 +0100
committerMatija Čupić <matteeyah@gmail.com>2017-11-28 14:22:29 +0100
commit8796e7278ecaf5e225b586499ac856957b5fad8b (patch)
tree00909c676e17497336b6ccd2364047b748c1a14a /app/finders/clusters_finder.rb
parent63b08da9cdb264a6c5597e1b47864f43b0336bed (diff)
downloadgitlab-ce-8796e7278ecaf5e225b586499ac856957b5fad8b.tar.gz
Refactor ClustersFinder
Diffstat (limited to 'app/finders/clusters_finder.rb')
-rw-r--r--app/finders/clusters_finder.rb30
1 files changed, 20 insertions, 10 deletions
diff --git a/app/finders/clusters_finder.rb b/app/finders/clusters_finder.rb
index 2b29c7bdf12..26bae3193da 100644
--- a/app/finders/clusters_finder.rb
+++ b/app/finders/clusters_finder.rb
@@ -1,19 +1,29 @@
class ClustersFinder
+ attr_reader :project, :user, :scope
+
def initialize(project, user, scope)
@project = project
@user = user
- @scope = scope
+ @scope = scope || :active
end
def execute
- clusters = case @scope
- when :all
- @project.clusters
- when :enabled
- @project.clusters.enabled
- when :disabled
- @project.clusters.disabled
- end
- clusters.map { |cluster| cluster.present(current_user: @user) }
+ clusters = project.clusters
+ filter_by_scope(clusters)
+ end
+
+ private
+
+ def filter_by_scope(clusters)
+ case @scope.to_sym
+ when :all
+ clusters
+ when :inactive
+ clusters.disabled
+ when :active
+ clusters.enabled
+ else
+ raise "Invalid scope #{@scope}"
+ end
end
end