Class: Getto::Roda::EntryPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/getto/roda/entry_point.rb

Overview

:nocov:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error:, time_zone:, app:, request:, config:, params:, request_logger:, exception_notifier:) ⇒ EntryPoint

Returns a new instance of EntryPoint.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/getto/roda/entry_point.rb', line 9

def initialize(
  error:, time_zone:,
  app:, request:,
  config:, params:,
  request_logger:, exception_notifier:)

  @error = error
  @time = Getto::Roda::Time.new(now: ::Time.now, time_zone: time_zone)

  @app = app
  @request = request
  @config = config
  @params = params

  @request_logger = check_signature(:request_logger, request_logger, [
    :debug,
    :info,
    :warn,
    :error,
    :fatal,
  ])
  @exception_notifier = check_signature(:exception_notifier, exception_notifier, [
    :notify_exception,
  ])

  @logger = Getto::Roda::Logger.new
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



47
48
49
# File 'lib/getto/roda/entry_point.rb', line 47

def 
  @account
end

#appObject (readonly)

Returns the value of attribute app.



47
48
49
# File 'lib/getto/roda/entry_point.rb', line 47

def app
  @app
end

#configObject (readonly)

Returns the value of attribute config.



47
48
49
# File 'lib/getto/roda/entry_point.rb', line 47

def config
  @config
end

#errorObject (readonly)

Returns the value of attribute error.



47
48
49
# File 'lib/getto/roda/entry_point.rb', line 47

def error
  @error
end

#exception_notifierObject (readonly)

Returns the value of attribute exception_notifier.



47
48
49
# File 'lib/getto/roda/entry_point.rb', line 47

def exception_notifier
  @exception_notifier
end

#loggerObject (readonly)

Returns the value of attribute logger.



47
48
49
# File 'lib/getto/roda/entry_point.rb', line 47

def logger
  @logger
end

#paramsObject (readonly)

Returns the value of attribute params.



47
48
49
# File 'lib/getto/roda/entry_point.rb', line 47

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



47
48
49
# File 'lib/getto/roda/entry_point.rb', line 47

def request
  @request
end

#timeObject (readonly)

Returns the value of attribute time.



47
48
49
# File 'lib/getto/roda/entry_point.rb', line 47

def time
  @time
end

Instance Method Details

#handle(controller) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/getto/roda/entry_point.rb', line 53

def handle(controller)
  params.merge! parse_params.to_h
  @account = 

  init_controller(controller).action
rescue error => e
  error! e

  if e.status >= 500
    exception_notifier.notify(e, data: request_data)
  end

  app.response.status = e.status

  {message: e.message.split(":").first}
rescue Exception => e
  error! e
  exception_notifier.notify_exception(e, data: request_data)
  raise e
ensure
  if @error_data
    @request_logger.error(name: :handle){ request_data }
  else
    @request_logger.info(name: :handle){ request_data }
  end
end