2018-09-11 19:08:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-31 11:35:23 +00:00
|
|
|
class TagsFinder
|
|
|
|
def initialize(repository, params)
|
|
|
|
@repository = repository
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
tags = @repository.tags_sorted_by(sort)
|
|
|
|
filter_by_name(tags)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def sort
|
|
|
|
@params[:sort].presence
|
|
|
|
end
|
|
|
|
|
|
|
|
def search
|
|
|
|
@params[:search].presence
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_by_name(tags)
|
|
|
|
if search
|
|
|
|
tags.select { |tag| tag.name.include?(search) }
|
|
|
|
else
|
|
|
|
tags
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|