Sha256: 493e874b713c042b28baaf892fd0dfc9f5bb71e12a47c14b5a9e267934d4be68

Contents?: true

Size: 982 Bytes

Versions: 1

Compression:

Stored size: 982 Bytes

Contents

module Hanami
  module Pagination
    class Pager
      attr_reader :pager

      def initialize(pager)
        @pager = pager
      end

      def next_page
        pager.next_page
      end

      def prev_page
        pager.prev_page
      end

      def total
        pager.total
      end

      def total_pages
        pager.total_pages
      end

      def current_page
        pager.current_page
      end

      def current_page?(page)
        pager.current_page == page
      end

      def pages_range(delta: 3)
        first = pager.current_page - delta
        first = first > 0 ? first : 1

        last = pager.current_page + delta
        last = last < pager.total_pages ? last : pager.total_pages

        (first..last).to_a
      end

      def all_pages
        (1..pager.total_pages).to_a
      end

      def first_page?
        pager.current_page == 1
      end

      def last_page?
        pager.current_page == pager.total_pages
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-pagination-0.2.0 lib/hanami/pagination/pager.rb