17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/filterable_by.rb', line 17
def merge(scope, unscoped, hash, name, **opts, &block)
key = name
positive = normalize(hash[key]) if hash.key?(key)
if positive.present?
sub = eval_scope(scope, unscoped, positive, **opts, &block)
return nil unless sub
scope = scope.merge(sub)
end
key = "#{name}_not"
negative = normalize(hash[key]) if hash.key?(key)
if negative.present?
sub = eval_scope(scope, unscoped, negative, **opts, &block)
return nil unless sub
scope = scope.merge(invert_where(sub))
end
scope
end
|