Sha256: afbb6e4e360613eba3ec877d637208734cb7016eae889b94b42578013790bc00

Contents?: true

Size: 651 Bytes

Versions: 2

Compression:

Stored size: 651 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 } }
    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

2 entries across 2 versions & 1 rubygems

Version Path
landable-1.7.1.rc1 app/models/landable/search_engine.rb
landable-1.7.0 app/models/landable/search_engine.rb