Sha256: a4f0af61fe25d0b2a0f0603c1aaa23fa03ad5fdc7d4e29880613f8e47e836636

Contents?: true

Size: 657 Bytes

Versions: 14

Compression:

Stored size: 657 Bytes

Contents

module Landable
  class SearchEngine
    def initialize(base_scope, filters, options = {})
      @scope = base_scope

      order! options[:order]
      limit! options[:limit]

      filter_by!(filters)
    end

    def results
      @scope
    end

    def meta
      { search: { total_results: @scope.count(:all) } }
    end

    def filter_by!(filters)
      raise NotImplementedError
    end

    def order!(order)
      @scope = @scope.order(order) if order
    end

    def limit!(limit)
      @scope = @scope.limit(limit) if limit
    end

    protected

    def as_array(value)
      array = Array(value)
      array if array.any?
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
landable-1.13.1 app/models/landable/search_engine.rb
landable-1.12.3 app/models/landable/search_engine.rb
landable-1.12.2 app/models/landable/search_engine.rb
landable-1.12.1 app/models/landable/search_engine.rb
landable-1.11.1 app/models/landable/search_engine.rb
landable-1.11.0 app/models/landable/search_engine.rb
landable-1.10.0.rc2 app/models/landable/search_engine.rb
landable-1.10.0.rc1 app/models/landable/search_engine.rb
landable-1.9.2 app/models/landable/search_engine.rb
landable-1.9.1 app/models/landable/search_engine.rb
landable-1.9.0 app/models/landable/search_engine.rb
landable-1.9.0.rc2 app/models/landable/search_engine.rb
landable-1.9.0.rc1 app/models/landable/search_engine.rb
landable-1.8.0 app/models/landable/search_engine.rb