blob: 26bfeeeee672166a33c80068c9e15b38d3a4a6cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
module Gitlab
module SQL
module Pattern
extend ActiveSupport::Concern
MIN_CHARS_FOR_PARTIAL_MATCHING = 3
class_methods do
def to_pattern(query)
if exact_matching?(query)
sanitize_sql_like(query)
else
"%#{sanitize_sql_like(query)}%"
end
end
def exact_matching?(query)
query.length < MIN_CHARS_FOR_PARTIAL_MATCHING
end
def partial_matching?(query)
query.length >= MIN_CHARS_FOR_PARTIAL_MATCHING
end
end
end
end
end
|