summaryrefslogtreecommitdiff
path: root/app/finders
diff options
context:
space:
mode:
authortiagonbotelho <tiagonbotelho@hotmail.com>2016-07-07 17:19:21 +0100
committertiagonbotelho <tiagonbotelho@hotmail.com>2016-07-19 19:30:10 +0100
commit766f9cf2202e7dbab758db4e03bc0e82500943eb (patch)
treeea32b90efaa908a95f8d0b55319c0e62fdda1312 /app/finders
parent81e57e783e8882de21d27d9191c09404ed7faca3 (diff)
downloadgitlab-ce-766f9cf2202e7dbab758db4e03bc0e82500943eb.tar.gz
implements the basic filter functionality
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/branches_finder.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/finders/branches_finder.rb b/app/finders/branches_finder.rb
new file mode 100644
index 00000000000..533076585c0
--- /dev/null
+++ b/app/finders/branches_finder.rb
@@ -0,0 +1,31 @@
+class BranchesFinder
+ def initialize(repository, params)
+ @repository = repository
+ @params = params
+ end
+
+ def execute
+ branches = @repository.branches_sorted_by(sort)
+ filter_by_name(branches)
+ end
+
+ private
+
+ attr_reader :repository, :params
+
+ def search
+ @params[:search].presence
+ end
+
+ def sort
+ @params[:sort].presence || 'name'
+ end
+
+ def filter_by_name(branches)
+ if search
+ branches.select { |branch| branch.name.include?(search) }
+ else
+ branches
+ end
+ end
+end