Sha256: b2e60d1ba43c6c25b884fbf9ad42772d95d3b848af441fdcac545fba04f177be

Contents?: true

Size: 751 Bytes

Versions: 17

Compression:

Stored size: 751 Bytes

Contents

# encoding: utf-8

module Hyperdrive
  module Middleware
    class Pagination
      attr_reader :default_per_page
      def initialize(app)
        @app = app
        @default_per_page = hyperdrive.config.fetch(:per_page) { 20 }
      end

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
hyperdrive-0.0.25 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.24 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.23 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.22 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.21 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.20 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.19 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.18 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.17 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.16 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.15 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.14 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.13 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.12 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.11 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.10 lib/hyperdrive/middleware/pagination.rb
hyperdrive-0.0.9 lib/hyperdrive/middleware/pagination.rb