Class: LifeGuard::Rack

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Rack.



5
6
7
8
9
10
11
12
13
# File 'lib/life_guard.rb', line 5

def initialize(app, opts={})
  @app = app
  @options = opts
  @header_key = @options[:header]
  @lambda = @options[:transformation]
  @failure_message = @options[:failure_message]
  @activepoolset = {}
  @config = ActiveRecord::Base.configurations.deep_dup
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/life_guard.rb', line 15

def call(env)
  begin
    switch_connection(env[@header_key]) if !env[@header_key].blank?
  rescue 
    return [404, {'Content-Type' => 'text/html'}, ["#{@failure_message}"]]
  else
    return @app.call(env)
  ensure
    change_connection(@config) if env[@header_key]
  end
end