2016-07-07 12:19:21 -04:00
|
|
|
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
|
2017-10-22 10:50:58 -04:00
|
|
|
branches.select { |branch| branch.name.upcase.include?(search.upcase) }
|
2016-07-07 12:19:21 -04:00
|
|
|
else
|
|
|
|
branches
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|