Commit 28fcf5c4 authored by Alexis Reigel's avatar Alexis Reigel

use functional style for tags finder

parent 4667b20c
......@@ -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]
return unless search
private
if search.empty?
@tags = ::ActsAsTaggableOn::Tag.none
return
def all_tags
::ActsAsTaggableOn::Tag.all
end
@tags =
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)
tags.named_like(search)
else
@tags.named(search)
tags.named(search)
end
end
def limit(tags)
tags.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord
end
def limit!
@tags = @tags.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord
def search
@params[:search]
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment