Sha256: 18ff68cb23f67fc2ff23c9db2f35f3a231d4dbfc354e51d3e4ead57ab991efa8

Contents?: true

Size: 935 Bytes

Versions: 5

Compression:

Stored size: 935 Bytes

Contents

require 'dynamic_sunspot_search/translator/all'
require 'dynamic_sunspot_search/translator/any'
require 'dynamic_sunspot_search/translator/fulltext'

module DynamicSunspotSearch
  module Translator
    module TextSearch
      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_text_search_hash(query_object, options)
        else
          raise NotImplementedError
        end
      end

      def self.apply_text_search_hash(query_object, options)
        All.apply(query_object, options.delete(:all))
        Any.apply(query_object, options.delete(:any))
        Fulltext.apply(query_object, options.delete(:fulltext))
        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/text_search.rb
dynamic_sunspot_search-0.1.3 lib/dynamic_sunspot_search/translator/text_search.rb
dynamic_sunspot_search-0.1.2 lib/dynamic_sunspot_search/translator/text_search.rb
dynamic_sunspot_search-0.1.1 lib/dynamic_sunspot_search/translator/text_search.rb
dynamic_sunspot_search-0.1.0 lib/dynamic_sunspot_search/translator/text_search.rb