Sha256: 172c03e7c5a0d2b09043faa8abda980c5bfeb22b61c7630f9eb2dd688c2de4fd

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 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
        MeiliSearch::Rails.logger
          .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

1 entries across 1 versions & 1 rubygems

Version Path
meilisearch-rails-0.10.2 lib/meilisearch/rails/pagination.rb