Class: Rack::Ok

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/ok.rb,
lib/rack/ok/version.rb

Constant Summary collapse

DEFAULT_REQUEST_PATH =
'/health'
DEFAULT_RESPONSE_BODY =
'OK'
VERSION =
'0.1.1'

Instance Method Summary collapse

Constructor Details

#initialize(app, body: DEFAULT_RESPONSE_BODY, path: DEFAULT_REQUEST_PATH) ⇒ Ok

Returns a new instance of Ok.

Parameters:

  • app (#call)
  • body (String) (defaults to: DEFAULT_RESPONSE_BODY)
  • path (String) (defaults to: DEFAULT_REQUEST_PATH)


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

def initialize(
  app,
  body: DEFAULT_RESPONSE_BODY,
  path: DEFAULT_REQUEST_PATH
)
  @app = app
  @body = body
  @path = path
end

Instance Method Details

#call(env) ⇒ Array

Returns Rack response.

Parameters:

  • env (Hash) —

    Rack env.

Returns:

  • (Array) —

    Rack response.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rack/ok.rb', line 26

def call(env)
  if env['PATH_INFO'] == @path
    [
      200,
      {
        'content-length' => @body.bytesize.to_s,
        'content-type' => 'text/plain'
      },
      [@body]
    ]
  else
    @app.call(env)
  end
end