Sha256: df3e781cdb67ea7263ed014a843c55e03647bd9079b2dce6ba3039a3cfa414cb

Contents?: true

Size: 791 Bytes

Versions: 11

Compression:

Stored size: 791 Bytes

Contents

# frozen_string_literal: true

module API
  ##
  # Défini le nombre max d'items par page à 100
  # `MAX_ITEMS_PAR_PAGE = 100`
  #
  # Défini le nombre par défaut d'items par page à 20
  # DEFAULT_NB_ITEMS_PAR_PAGE = 20
  module PaginationConcern
    extend ActiveSupport::Concern

    included do |base|
      base.const_set :MAX_ITEMS_PAR_PAGE, 100
      base.const_set :DEFAULT_NB_ITEMS_PAR_PAGE, 20

      def pagination
        @pagination ||=
          begin
            par_page = (params[:per_page] || self.class::DEFAULT_NB_ITEMS_PAR_PAGE).to_i
            par_page = self.class::MAX_ITEMS_PAR_PAGE if par_page > self.class::MAX_ITEMS_PAR_PAGE
            page = (params[:page] || 1).to_i
            { page: page, per_page: par_page }
          end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
captive-api-0.2.12 app/controllers/concerns/api/pagination_concern.rb
captive-api-0.2.11 app/controllers/concerns/api/pagination_concern.rb
captive-api-0.2.9 app/controllers/concerns/api/pagination_concern.rb
captive-api-0.2.8 app/controllers/concerns/api/pagination_concern.rb
captive-api-0.2.7 app/controllers/concerns/api/pagination_concern.rb
captive-api-0.2.6 app/controllers/concerns/api/pagination_concern.rb
captive-api-0.2.5 app/controllers/concerns/api/pagination_concern.rb
captive-api-0.2.4 app/controllers/concerns/api/pagination_concern.rb
captive-api-0.2.3 app/controllers/concerns/api/pagination_concern.rb
captive-api-0.2.2 app/controllers/concerns/api/pagination_concern.rb
captive-api-0.1.0.alpha app/controllers/concerns/api/pagination_concern.rb