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, path = '/active_record_status') ⇒ ActiveRecordStatus
constructor
A new instance of ActiveRecordStatus.
Constructor Details
#initialize(app, path = '/active_record_status') ⇒ ActiveRecordStatus
Returns a new instance of ActiveRecordStatus.
3 4 5 |
# File 'lib/rack/active_record_status.rb', line 3 def initialize(app, path='/active_record_status') @app, @path = app, path end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/rack/active_record_status.rb', line 7 def call(env) if @path == env['PATH_INFO'] get_status else @app.call(env) end end |
#get_status ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rack/active_record_status.rb', line 15 def get_status begin ActiveRecord::Base.connection.select_all('select 1') body = "OK #{Time.now}" [200, {'Content-Type' => 'text/plain'}, body] rescue body = ['ERROR', "#{$!.class}: #{$!.}", "Backtrace:"] + $!.backtrace body *= "\n" [500, {'Content-Type' => 'text/plain'}, body] end end |