Sha256: eeea4d3bf9eee60aa1d6a835f7b1f3da15e52444ac071e01230250a86790bb95

Contents?: true

Size: 512 Bytes

Versions: 2

Compression:

Stored size: 512 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, 25).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.1 lib/fetcheable_on_api/pagineable.rb
fetcheable_on_api-0.1.0 lib/fetcheable_on_api/pagineable.rb