use functional style for tags finder

This commit is contained in:
Alexis Reigel 2019-02-21 20:26:20 +01:00
parent 4667b20c00
commit 28fcf5c4bf
No known key found for this signature in database
GPG Key ID: 55ADA7C7B683B329
1 changed files with 21 additions and 21 deletions

View File

@ -10,34 +10,34 @@ module Autocomplete
end
def execute
@tags = ::ActsAsTaggableOn::Tag.all
search!
limit!
@tags
tags = all_tags
tags = filter_by_name(tags)
limit(tags)
end
def search!
search = @params[:search]
private
return unless search
def all_tags
::ActsAsTaggableOn::Tag.all
end
if search.empty?
@tags = ::ActsAsTaggableOn::Tag.none
return
def filter_by_name(tags)
return tags unless search
return tags.none if search.empty?
if search.length >= Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING
tags.named_like(search)
else
tags.named(search)
end
@tags =
if search.length >= Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING
@tags.named_like(search)
else
@tags.named(search)
end
end
def limit!
@tags = @tags.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord
def limit(tags)
tags.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord
end
def search
@params[:search]
end
end
end