Class: Rack::Heartbeat

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

Overview

A heartbeat mechanism for the server. This will add a / endpoint that responds to OPTIONS, returning status 200 when executed.

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

DEFAULT_ALLOW =
%w(HEAD GET PUT DELETE OPTIONS)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, allow = nil) ⇒ Heartbeat

Returns a new instance of Heartbeat.



10
11
12
13
# File 'lib/rack/heartbeat.rb', line 10

def initialize(app, allow = nil)
  @app = app
  @allow = allow || DEFAULT_ALLOW
end

Instance Attribute Details

#allowObject

Returns the value of attribute allow.



8
9
10
# File 'lib/rack/heartbeat.rb', line 8

def allow
  @allow
end

Class Method Details

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



24
25
26
# File 'lib/rack/heartbeat.rb', line 24

def self.setup
  yield self
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/rack/heartbeat.rb', line 15

def call(env)
  if env['PATH_INFO'] == "/" && (env['REQUEST_METHOD']||'').upcase == 'OPTIONS'
    NewRelic::Agent.ignore_transaction if defined? NewRelic
    [200, {"Content-Type" => "text/plain", "Allow" => @allow.join(',')}, ["OK"]]
  else
    @app.call(env)
  end
end