From 766f9cf2202e7dbab758db4e03bc0e82500943eb Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Thu, 7 Jul 2016 17:19:21 +0100 Subject: implements the basic filter functionality --- app/finders/branches_finder.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 app/finders/branches_finder.rb (limited to 'app/finders') 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 -- cgit v1.2.1