gitlab-org--gitlab-foss/lib/gitlab/sql/pattern.rb
Hiroyuki Sato 12633b46b6 Refactor
2017-08-29 18:00:03 +09:00

23 lines
473 B
Ruby

module Gitlab
module SQL
module Pattern
extend ActiveSupport::Concern
MIN_CHARS_FOR_PARTIAL_MATCHING = 3
class_methods do
def to_pattern(query)
if partial_matching?(query)
"%#{sanitize_sql_like(query)}%"
else
sanitize_sql_like(query)
end
end
def partial_matching?(query)
query.length >= MIN_CHARS_FOR_PARTIAL_MATCHING
end
end
end
end
end