Class: Rack::ActiveRecordStatus
- Inherits:
-
Object
- Object
- Rack::ActiveRecordStatus
- Defined in:
- lib/rack/active_record_status.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #get_status ⇒ Object
-
#initialize(app, options = {}) ⇒ ActiveRecordStatus
constructor
A new instance of ActiveRecordStatus.
Constructor Details
#initialize(app, options = {}) ⇒ ActiveRecordStatus
Returns a new instance of ActiveRecordStatus.
3 4 5 6 7 8 9 10 |
# File 'lib/rack/active_record_status.rb', line 3 def initialize(app, ={}) @app = app # Support legacy arguments (0.4.1 and below) = {:path => } if .is_a?(String) @path = [:path] || '/app_status' @response = [:response] || "OK\n" end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/rack/active_record_status.rb', line 12 def call(env) if @path == env['PATH_INFO'] get_status else @app.call(env) end end |
#get_status ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack/active_record_status.rb', line 20 def get_status begin # Check that the application is connected to the database ActiveRecord::Base.connection.select_all('select 1') # Success [200, {'Content-Type' => 'text/plain'}, [@response]] rescue body = ['ERROR', "#{$!.class}: #{$!.}", "Backtrace:"] + $!.backtrace body *= "\n" [500, {'Content-Type' => 'text/plain'}, [body]] end end |