Sha256: 5495a703a2f6bed96373c51755e4c2293e740d3a5d05a4381c695b831848211f

Contents?: true

Size: 938 Bytes

Versions: 5

Compression:

Stored size: 938 Bytes

Contents

module DynamicSunspotSearch
  module Translator
    module Without
      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
    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/without.rb
dynamic_sunspot_search-0.1.3 lib/dynamic_sunspot_search/translator/without.rb
dynamic_sunspot_search-0.1.2 lib/dynamic_sunspot_search/translator/without.rb
dynamic_sunspot_search-0.1.1 lib/dynamic_sunspot_search/translator/without.rb
dynamic_sunspot_search-0.1.0 lib/dynamic_sunspot_search/translator/without.rb