Sha256: 2db93cbc4267ec037e49f5e3ea6d79f3a99fb6d68931eafbbbfd1903aadbed62

Contents?: true

Size: 657 Bytes

Versions: 2

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)
      fail 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.14.0 app/models/landable/search_engine.rb
landable-1.13.2 app/models/landable/search_engine.rb