/
indexes_check.rb
45 lines (36 loc) · 1.07 KB
/
indexes_check.rb
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Picky
module Query
class IndexesCheck
class << self
# Returns the right combinations strategy for
# a number of query indexes.
#
# Currently it isn't possible using Memory and Redis etc.
# indexes in the same query index group.
#
# Picky will raise a Query::Indexes::DifferentBackendsError.
#
def check_backends indexes
backends = indexes.map &:backend
backends.uniq! &:class
raise_different backends if backends.size > 1
backends
end
def raise_different backends
raise DifferentBackendsError.new(backends)
end
end
end
# Currently it isn't possible using Memory and Redis etc.
# indexes in the same query index group.
#
class DifferentBackendsError < StandardError
def initialize backends
@backends = backends
end
def to_s
"Currently it isn't possible to mix Indexes with backends #{@backends.join(" and ")} in the same Search instance."
end
end
end
end