Sha256: 14cf1fa2680a5e30593ad6150f55196ee365630fce3aa191813a69d998f63899

Contents?: true

Size: 633 Bytes

Versions: 2

Compression:

Stored size: 633 Bytes

Contents

# encoding: utf-8

module Hyperdrive
  module Middleware
    class Pagination
      def initialize(app)
        @app = app
      end

      def call(env)
        if %(GET HEAD).include? env['REQUEST_METHOD']
          env['hyperdrive.page'] = env['hyperdrive.params'].delete(:page) { 1 }
          env['hyperdrive.page'] = 1 if env['hyperdrive.page'].to_i < 1
          env['hyperdrive.per_page'] = env['hyperdrive.params'].delete(:per_page) { hyperdrive.config.fetch(:per_page) { 20 } }
          env['hyperdrive.per_page'] = 20 if env['hyperdrive.per_page'].to_i == 0
        end
        @app.call(env)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hyperdrive-0.0.8 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.7 lib/hyperdrive/middleware/pagination.rb