Sha256: 44a53761efa030e59574656bca211a5e94006c10874d2dfaee405bc198d739fb

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

module MeiliSearch
  module Rails
    module Pagination
      autoload :WillPaginate, 'meilisearch/rails/pagination/will_paginate'
      autoload :Kaminari, 'meilisearch/rails/pagination/kaminari'

      def self.create(results, total_hits, options = {})
        pagination_backend = MeiliSearch::Rails.configuration[:pagination_backend]

        if pagination_backend.nil? || (is_pagy = pagination_backend.to_s == 'pagy')
          log_pagy_error if is_pagy

          return results
        end

        load_pagination!(pagination_backend, results, total_hits, options)
      end

      def self.log_pagy_error
        (::Rails.logger || Logger.new($stdout))
          .warning('[meilisearch-rails] Remove `pagination_backend: :pagy` from your initializer, `pagy` it is not required for `pagy`')
      end

      def self.load_pagination!(pagination_backend, results, total_hits, options)
        ::MeiliSearch::Rails::Pagination
          .const_get(pagination_backend.to_s.classify)
          .create(results, total_hits, options)
      rescue NameError
        raise(BadConfiguration, 'Invalid `pagination_backend:` configuration, check your initializer.')
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
meilisearch-rails-0.10.1 lib/meilisearch/rails/pagination.rb
meilisearch-rails-0.10.0 lib/meilisearch/rails/pagination.rb
meilisearch-rails-0.9.1 lib/meilisearch/rails/pagination.rb
meilisearch-rails-0.9.0 lib/meilisearch/rails/pagination.rb
meilisearch-rails-0.8.1 lib/meilisearch/rails/pagination.rb
meilisearch-rails-0.8.0 lib/meilisearch/rails/pagination.rb