Sha256: 02188b41d844eace097a1f213a2673a87fd722649ba6b0e0ad1a6586aedb3113

Contents?: true

Size: 587 Bytes

Versions: 2

Compression:

Stored size: 587 Bytes

Contents

# frozen_string_literal: true

module FetcheableOnApi
  module Pagineable
    #
    # Supports
    #

    #
    # Public class methods
    #

    #
    # Public instance methods
    #

    #
    # Protected instance methods
    #
    protected

    def apply_pagination(collection)
      return collection if params[:page].blank?

      limit = params[:page].fetch(
        :size,
        FetcheableOnApi.configuration.pagination_default_size
      ).to_i

      offset = (params[:page].fetch(:number, 1).to_i - 1) * limit

      collection.limit(limit).offset(offset)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fetcheable_on_api-0.1.3 lib/fetcheable_on_api/pagineable.rb
fetcheable_on_api-0.1.2 lib/fetcheable_on_api/pagineable.rb