Class: RackDriverSelect

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/rack_driver_select.rb

Constant Summary collapse

HEADER_TO_ENV_MAP =
{
  'HTTP_X_DELTACLOUD_DRIVER' => :driver,
  'HTTP_X_DELTACLOUD_PROVIDER' => :provider
}

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ RackDriverSelect

Returns a new instance of RackDriverSelect.



3
4
5
6
# File 'lib/sinatra/rack_driver_select.rb', line 3

def initialize(app, opts={})
  @app = app
  @opts = opts
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sinatra/rack_driver_select.rb', line 13

def call(env)
  original_settings = { }
  HEADER_TO_ENV_MAP.each do |header, name|
    original_settings[name] = Thread.current[name]
    new_setting = extract_header(env, header)
    Thread.current[name] = new_setting if new_setting
  end
  @app.call(env)
ensure
  original_settings.each { |name, value| Thread.current[name] = value }
end

#extract_header(env, header) ⇒ Object



25
26
27
# File 'lib/sinatra/rack_driver_select.rb', line 25

def extract_header(env, header)
  env[header].downcase if env[header]
end