Class: Heartcheck::App

Inherits:
Object
  • Object
show all
Defined in:
lib/heartcheck/app.rb

Constant Summary collapse

ROUTE_TO_CONTROLLER =

A hash with paths as keys and controllers as values we use it in #dispath_action to routes the requests

{
  '/' => Controllers::Essential,
  '' => Controllers::Essential,
  '/functional' => Controllers::Functional,
  '/dev' => Controllers::Dev,
  '/info' => Controllers::Info,
  '/health_check' => Controllers::HealthCheck
}

Instance Method Summary collapse

Constructor Details

#initialize(app = nil) ⇒ void

Sets up the rack application.

Parameters:

  • app (RackApp) (defaults to: nil)

    is a rack app where heartcheck is included.


27
28
29
# File 'lib/heartcheck/app.rb', line 27

def initialize(app = nil)
  @app = app
end

Instance Method Details

#call(env) ⇒ Array

Sets up the rack application.

Parameters:

  • env (Hash)

    is an instance of Hash that includes CGI-like headers.

Returns:

  • (Array)

    must be an array that contains

    • The HTTP response code

    • A Hash of headers

    • The response body, which must respond to each


39
40
41
42
43
44
45
# File 'lib/heartcheck/app.rb', line 39

def call(env)
  req = Rack::Request.new(env)

  [200, { 'Content-Type' => 'application/json' }, [dispatch_action(req)]]
rescue Heartcheck::Errors::RoutingError
  [404, { 'Content-Type' => 'application/json' }, ['Not found']]
end