Module: DynamicSunspotSearch::Translator::Scope

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

Class Method Summary collapse

Class Method Details

.apply(query_object, options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dynamic_sunspot_search/translator/scope.rb', line 9

def self.apply(query_object, options)
  return unless options.present?
  case options
  when Array
    options.each do |option|
      apply(query_object, option)
    end
  when Hash
    apply_scope_hash(query_object, options)
  else
    raise NotImplementedError
  end
end

.apply_scope_hash(query_object, options) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
# File 'lib/dynamic_sunspot_search/translator/scope.rb', line 23

def self.apply_scope_hash(query_object, options)
  Scope.apply(query_object, options.delete(:scope))
  With.apply(query_object, options.delete(:with))
  Without.apply(query_object, options.delete(:without))
  AnyOf.apply(query_object, options.delete(:any_of))
  AllOf.apply(query_object, options.delete(:all_of))
  raise ArgumentError.new("Unknown keys detected: #{options.keys}") unless options.blank?
end