Class: Makanai::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/makanai/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(router:) ⇒ Application

Returns a new instance of Application.



13
14
15
16
# File 'lib/makanai/application.rb', line 13

def initialize(router:)
  @router = router
  @config = Settings
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



18
19
20
# File 'lib/makanai/application.rb', line 18

def config
  @config
end

#requestObject (readonly)

Returns the value of attribute request.



18
19
20
# File 'lib/makanai/application.rb', line 18

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



18
19
20
# File 'lib/makanai/application.rb', line 18

def response
  @response
end

#routerObject (readonly)

Returns the value of attribute router.



18
19
20
# File 'lib/makanai/application.rb', line 18

def router
  @router
end

Instance Method Details

#call(env) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/makanai/application.rb', line 29

def call(env)
  @request = Makanai::Request.new(env)
  @response = Makanai::Response.new
  route_result = execute_route
  return route_result.result if route_result.instance_of?(Response)
  @response.body << execute_route
  @response.result
end

#run!Object



20
21
22
23
24
25
26
27
# File 'lib/makanai/application.rb', line 20

def run!
  app_config = config.rack_app_config
  handler = Rack::Handler.get(app_config[:handler])
  handler.run(self, **{ Host: app_config[:host], Port: app_config[:port] })
rescue Interrupt
  handler.shutdown
  puts '==== Goodbye! :) ===='
end