Class: OperationsMiddleware
- Inherits:
-
Object
- Object
- OperationsMiddleware
- Defined in:
- lib/operations_middleware.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
writeonly
Sets the attribute app_name.
-
#file_root ⇒ Object
Returns the value of attribute file_root.
-
#heartbeat ⇒ Object
Returns the value of attribute heartbeat.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) {|_self| ... } ⇒ OperationsMiddleware
constructor
A new instance of OperationsMiddleware.
Constructor Details
#initialize(app) {|_self| ... } ⇒ OperationsMiddleware
Returns a new instance of OperationsMiddleware.
5 6 7 8 9 |
# File 'lib/operations_middleware.rb', line 5 def initialize(app) @app = app @heartbeat = {} yield self if block_given? end |
Instance Attribute Details
#app_name=(value) ⇒ Object
Sets the attribute app_name
2 3 4 |
# File 'lib/operations_middleware.rb', line 2 def app_name=(value) @app_name = value end |
#file_root ⇒ Object
Returns the value of attribute file_root.
3 4 5 |
# File 'lib/operations_middleware.rb', line 3 def file_root @file_root end |
#heartbeat ⇒ Object
Returns the value of attribute heartbeat.
3 4 5 |
# File 'lib/operations_middleware.rb', line 3 def heartbeat @heartbeat end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/operations_middleware.rb', line 11 def call(env) return @app.call(env) unless env['PATH_INFO'] =~ %r{^/ops/(heartbeat|version)(?:/(\w+))?/?$} @request_headers = env @status = 200 @headers = {} if $1 == 'heartbeat' if $2 check_heartbeat($2) else @body = "#{app_name} is OK" end else @body = version_template end @headers['Content-Type'] = "text/html" @headers['Content-Length'] = @body.length.to_s [@status, @headers, @body] end |