Sha256: 0b1e4e5abb98cb3e43765b0ee30c78739f8177cc3c37632e003cda492e47affa

Contents?: true

Size: 936 Bytes

Versions: 3

Compression:

Stored size: 936 Bytes

Contents

#
# Pagination methods for Kaminari
# https://github.com/kaminari/kaminari
#
module ActiveManageable
  module Pagination
    module Kaminari
      extend ActiveSupport::Concern

      class_methods do
        # Sets the default page size to use when fetching records in the index method
        # if the index :options argument does not contain a :page hash with :size key;
        # accepting an integer.
        #
        # For example:-
        #   default_page_size 5
        def default_page_size(page_size)
          defaults[:page] = {size: page_size.to_i}
        end
      end

      included do
        private

        def page(opts)
          @target = @target.page(page_number(opts)).per(page_size(opts))
        end

        def page_number(opts)
          opts.try(:[], :number)
        end

        def page_size(opts)
          opts.try(:[], :size) || defaults.dig(:page, :size)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_manageable-0.1.2 lib/active_manageable/pagination/kaminari.rb
active_manageable-0.1.1 lib/active_manageable/pagination/kaminari.rb
active_manageable-0.1.0 lib/active_manageable/pagination/kaminari.rb