Class: Mobvious::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/mobvious/manager.rb

Overview

Rack middleware that enables device type detection for requests.

Use Mobvious.config to set which strategies to use.

Look into Mobvious::Strategies for predefined strategies or write your own.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Manager

Create a new instance of this rack middleware.

Parameters:

  • app

    Rack application that can be called.



13
14
15
# File 'lib/mobvious/manager.rb', line 13

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

Perform the device type detection and call the inner Rack application.

Parameters:

  • env

    Rack environment.

Returns:

  • rack response [status, headers, body]



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mobvious/manager.rb', line 21

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

  status, headers, body = @app.call(env)

  response = Rack::Response.new(body, status, headers)
  response_callback(request, response)

  [status, headers, body]
end