From 2972b209b3f54edbfaf6195a92cf0ac367726ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arist=C3=B3teles=20Coutinho?= Date: Mon, 27 Nov 2023 13:43:30 -0300 Subject: [PATCH 01/25] documetation: update --- lib/lenna/base.rb | 13 ++++++- lib/lenna/middleware/default/error_handler.rb | 8 ++++ lib/lenna/middleware/default/logging.rb | 5 +++ lib/lenna/router.rb | 38 ++++++++++++++++++- lib/lenna/router/builder.rb | 17 +++++++++ lib/lenna/router/cache.rb | 24 +++++++++--- lib/lenna/router/namespace_stack.rb | 13 ++++--- lib/lenna/router/request.rb | 21 +++++++++- lib/lennarb/array_extensions.rb | 9 +++++ 9 files changed, 133 insertions(+), 15 deletions(-) diff --git a/lib/lenna/base.rb b/lib/lenna/base.rb index 2990340..caedf34 100644 --- a/lib/lenna/base.rb +++ b/lib/lenna/base.rb @@ -10,13 +10,21 @@ module Lenna # The base class is used to start the server. + # class Base < Router + # The default port is 3000 + # DEFAULT_PORT = 3000 private_constant :DEFAULT_PORT + + # The default host is localhost + # DEFAULT_HOST = 'localhost' private_constant :DEFAULT_HOST - # This method will start the server. + # This method will start the puma server and listen on the specified port + # and host. The default port is 3000 and the default host is localhost. + # Use only in development. # # @param port [Integer] The port to listen on (default: 3000) # @param host [String] The host to listen on (default: ' @@ -27,7 +35,7 @@ class Base < Router # app.listen(8080) # # => ⚡ Listening on localhost:8080 # - # or specify the host and port + # # or specify the host and port # # app = Lenna::Base.new # app.listen(8000, host: '0.0.0.0') @@ -38,6 +46,7 @@ class Base < Router # @todo: Add Lenna::Server to handle the server logic # # @since 0.1.0 + # def listen(port = DEFAULT_PORT, host: DEFAULT_HOST, **) puts "⚡ Listening on #{host}:#{port}. \n Use Ctrl-C to stop the server." diff --git a/lib/lenna/middleware/default/error_handler.rb b/lib/lenna/middleware/default/error_handler.rb index 934e99b..e70f45e 100644 --- a/lib/lenna/middleware/default/error_handler.rb +++ b/lib/lenna/middleware/default/error_handler.rb @@ -6,6 +6,7 @@ module Lenna module Middleware module Default # This middleware will handle errors. + # module ErrorHandler extend self @@ -37,6 +38,7 @@ def call(req, res, next_middleware) # @return [void] # # @api private + # def render_error_page(error, env, req, res) case req.headers['Content-Type'] in 'application/json' then render_json(error, env, res) @@ -52,6 +54,7 @@ def render_error_page(error, env, req, res) # @return [void] # # @api private + # def render_json(error, env, res) case env['RACK_ENV'] in 'development' | 'test' then res.json( @@ -72,6 +75,7 @@ def render_json(error, env, res) # @return [void] # # @api private + # def render_html(error, env, res) res.html(error_page(error, env), status: 500) end @@ -83,6 +87,7 @@ def render_html(error, env, res) # @return [void] # # @api private + # def log_error(env, error) env['rack.errors'].puts error.message env['rack.errors'].puts error.backtrace.join("\n") @@ -90,6 +95,7 @@ def log_error(env, error) end # This method will render the error page. + # def error_page(error, env) style = <<-STYLE