Sha256: 003981c7b6c8b3db804094e189e9d515ce5c6905d89686aae7a4bc016fe95447

Contents?: true

Size: 665 Bytes

Versions: 2

Compression:

Stored size: 665 Bytes

Contents

module PaginateResponder::Adapter

  # Pagination adapter for kaminari.
  #
  class KaminariAdapter < Base

    def suitable?
      defined?(:Kaminari) and 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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paginate-responder-1.4.1 lib/paginate-responder/adapter/kaminari_adapter.rb
paginate-responder-1.4.0 lib/paginate-responder/adapter/kaminari_adapter.rb