debian-mirror-gitlab/app/finders/branches_finder.rb

34 lines
571 B
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
class BranchesFinder
2018-03-27 19:54:05 +05:30
def initialize(repository, params = {})
2016-08-24 12:49:21 +05:30
@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
2018-03-17 18:26:18 +05:30
branches.select { |branch| branch.name.upcase.include?(search.upcase) }
2016-08-24 12:49:21 +05:30
else
branches
end
end
end