Class: UssdEngine::Middleware::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/ussd_engine/middleware/pagination.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Pagination

Returns a new instance of Pagination.



4
5
6
# File 'lib/ussd_engine/middleware/pagination.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ussd_engine/middleware/pagination.rb', line 8

def call(env)
  @env = env
  request = Rack::Request.new(env)
  @session = request.session

  if intercept?
    @env["ussd_engine.response"] = handle_intercepted_request
    [200, {}, [""]]
  else
    @session.delete "ussd_engine.pagination"
    res = @app.call(env)

    if @env["ussd_engine.response"].present?
      @env["ussd_engine.response"] = maybe_paginate @env["ussd_engine.response"]
    end

    res
  end
end