Class: Pechkin::App

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

Overview

Rack application to handle requests

Constant Summary collapse

DEFAULT_CONTENT_TYPE =
{ 'Content-Type' => 'application/json' }.freeze
DEFAULT_HEADERS =
{}.merge(DEFAULT_CONTENT_TYPE)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ App

Returns a new instance of App.



9
10
11
# File 'lib/pechkin/app/app.rb', line 9

def initialize(logger)
  @logger = logger
end

Instance Attribute Details

#handlerObject

Returns the value of attribute handler.



7
8
9
# File 'lib/pechkin/app/app.rb', line 7

def handler
  @handler
end

#loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/pechkin/app/app.rb', line 7

def logger
  @logger
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pechkin/app/app.rb', line 13

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

  # Stub for favicon.ico
  if req.path_info == '/favicon.ico'
    return response(405, '') # Return empty response 405 Method Not Allowed
  end

  result = RequestHandler.new(handler, req, logger).handle
  response(200, result)
rescue AppError => e
  proces_app_error(req, e)
rescue StandardError => e
  process_unhandled_error(req, e)
end