Sha256: 2e0e91f0f53ea39d46245af4216437808fcfa06b37b0c2cce0c6167be0fb490d

Contents?: true

Size: 831 Bytes

Versions: 6

Compression:

Stored size: 831 Bytes

Contents

module PaginateResponder
  #
  # Pagination adapter for kaminari.
  #
  class KaminariAdapter < Base
    def paginate
      resource.page(page).per(per_page)
    end

    def default_per_page
      Kaminari.config.default_per_page
    end

    def default_max_per_page
      Kaminari.config.max_per_page
    end

    def total_pages
      return resource.total_pages if resource.respond_to? :total_pages
      return resource.num_pages   if resource.respond_to? :num_pages
    end

    def total_count
      resource.total_count if resource.respond_to? :total_count
    end

    class << self
      def suitable?(resource, responder)
        resource.respond_to?(:page) and not resource.respond_to?(:paginate)
      end
    end
  end

  if defined?(:Kaminari)
    ::Responders::PaginateResponder.register KaminariAdapter
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
paginate-responder-2.1.0 lib/paginate-responder/kaminari_adapter.rb
paginate-responder-2.0.0 lib/paginate-responder/kaminari_adapter.rb
paginate-responder-1.8.0 lib/paginate-responder/kaminari_adapter.rb
paginate-responder-1.7.0 lib/paginate-responder/kaminari_adapter.rb
paginate-responder-1.6.0 lib/paginate-responder/kaminari_adapter.rb
paginate-responder-1.6.0.b0 lib/paginate-responder/kaminari_adapter.rb