summaryrefslogtreecommitdiff
path: root/app/finders
diff options
context:
space:
mode:
authorAlexis Reigel <alexis.reigel.ext@siemens.com>2019-02-21 20:26:20 +0100
committerAlexis Reigel <alexis.reigel.ext@siemens.com>2019-02-27 20:20:24 +0100
commit28fcf5c4bfe19dfb90363e201156ad68b7263f6d (patch)
tree09ba251a7536ea4ccc6ff10d4ef10f2d851fecc3 /app/finders
parent4667b20c007c4bce248ac6cc458414fefa058bb8 (diff)
downloadgitlab-ce-28fcf5c4bfe19dfb90363e201156ad68b7263f6d.tar.gz
use functional style for tags finder
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb38
1 files changed, 19 insertions, 19 deletions
diff --git a/app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb b/app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb
index 71dffb72dce..f38c187799c 100644
--- a/app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb
+++ b/app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb
@@ -10,34 +10,34 @@ module Autocomplete
end
def execute
- @tags = ::ActsAsTaggableOn::Tag.all
+ tags = all_tags
+ tags = filter_by_name(tags)
+ limit(tags)
+ end
- search!
- limit!
+ private
- @tags
+ def all_tags
+ ::ActsAsTaggableOn::Tag.all
end
- def search!
- search = @params[:search]
-
- return unless search
+ def filter_by_name(tags)
+ return tags unless search
+ return tags.none if search.empty?
- if search.empty?
- @tags = ::ActsAsTaggableOn::Tag.none
- return
+ if search.length >= Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING
+ tags.named_like(search)
+ else
+ tags.named(search)
end
+ end
- @tags =
- if search.length >= Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING
- @tags.named_like(search)
- else
- @tags.named(search)
- 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