gitlab-org--gitlab-foss/lib/gitlab/sql/pattern.rb

24 lines
473 B
Ruby
Raw Normal View History

module Gitlab
module SQL
2017-08-28 18:14:41 -04:00
module Pattern
extend ActiveSupport::Concern
2017-08-28 18:14:41 -04:00
MIN_CHARS_FOR_PARTIAL_MATCHING = 3
2017-08-28 18:14:41 -04:00
class_methods do
def to_pattern(query)
2017-08-29 05:00:03 -04:00
if partial_matching?(query)
2017-08-28 18:14:41 -04:00
"%#{sanitize_sql_like(query)}%"
2017-08-29 05:00:03 -04:00
else
sanitize_sql_like(query)
2017-08-28 18:14:41 -04:00
end
end
2017-08-28 18:14:41 -04:00
def partial_matching?(query)
query.length >= MIN_CHARS_FOR_PARTIAL_MATCHING
end
end
end
end
end