Sha256: 84605de0e11920129599d7ae623d46aa8aec2f7a89b4b6a3ef743dd2d5f427f5

Contents?: true

Size: 733 Bytes

Versions: 3

Compression:

Stored size: 733 Bytes

Contents

module PaginateResponder::Adapter

  # Pagination adapter for kaminari.
  #
  class KaminariAdapter < Base

    def suitable?
      resource.respond_to?(:page) and not resource.respond_to?(:paginate)
    end

    def paginate(opts)
      resource.page(opts[:page]).per(opts[:per_page])
    end

    def defaults
      {
          :per_page => Kaminari.config.default_per_page,
          :max_per_page => Kaminari.config.max_per_page
      }
    end

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
paginate-responder-1.5.0 lib/paginate-responder/adapter/kaminari_adapter.rb
paginate-responder-1.4.2 lib/paginate-responder/adapter/kaminari_adapter.rb
paginate-responder-1.4.2.beta0 lib/paginate-responder/adapter/kaminari_adapter.rb