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