Sha256: d02f877a7ff990e032248e1226f27548c71fe0fcce0a5fd46f983710e00e7958

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

require 'dynamic_sunspot_search/translator/all_of'
require 'dynamic_sunspot_search/translator/any_of'
require 'dynamic_sunspot_search/translator/with'
require 'dynamic_sunspot_search/translator/without'

module DynamicSunspotSearch
  module Translator
    module Scope
      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

      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
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dynamic_sunspot_search-0.1.4 lib/dynamic_sunspot_search/translator/scope.rb
dynamic_sunspot_search-0.1.3 lib/dynamic_sunspot_search/translator/scope.rb
dynamic_sunspot_search-0.1.2 lib/dynamic_sunspot_search/translator/scope.rb
dynamic_sunspot_search-0.1.1 lib/dynamic_sunspot_search/translator/scope.rb
dynamic_sunspot_search-0.1.0 lib/dynamic_sunspot_search/translator/scope.rb