Module: DynamicSunspotSearch::Translator::Without

Defined in:
lib/dynamic_sunspot_search/translator/without.rb

Class Method Summary collapse

Class Method Details

.apply(query_object, without_scope) ⇒ Object



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
# File 'lib/dynamic_sunspot_search/translator/without.rb', line 4

def self.apply(query_object, without_scope)
  return unless without_scope.present?
  query_object.tap do |search|
    case without_scope
    when Array
      return without_scope.map do |filter|
        apply(search, filter)
      end
    when Hash
      return without_scope.map do |key, value|
        case value
        when Hash
          value.map do |method, *args|
            search.without(key).send(method, *args)
          end
        when /^range:.+\.\..+$/
          range_start, range_end = value.match(/^range:(.+)\.\.(.+)$/).values_at(1, 2)
          search.without(key, (range_start..range_end))
        else
          search.without(key, value)
        end
      end
    end
  end
end