Use nested module declaration

This commit is contained in:
Sdogruyol 2016-07-17 14:43:13 +03:00
parent 4edebcf8eb
commit f7484d14d3
9 changed files with 176 additions and 160 deletions

View file

@ -1,5 +1,6 @@
# All loggers must inherit from `Kemal::BaseLogHandler`. module Kemal
class Kemal::BaseLogHandler < HTTP::Handler # All loggers must inherit from `Kemal::BaseLogHandler`.
class Kemal::BaseLogHandler < HTTP::Handler
def initialize def initialize
end end
@ -9,4 +10,5 @@ class Kemal::BaseLogHandler < HTTP::Handler
def write(message) def write(message)
end end
end
end end

View file

@ -1,4 +1,5 @@
class Kemal::CommonLogHandler < Kemal::BaseLogHandler module Kemal
class CommonLogHandler < Kemal::BaseLogHandler
@handler : IO::FileDescriptor @handler : IO::FileDescriptor
getter handler getter handler
@ -30,4 +31,5 @@ class Kemal::CommonLogHandler < Kemal::BaseLogHandler
"#{(millis * 1000).round(2)}µs" "#{(millis * 1000).round(2)}µs"
end end
end
end end

View file

@ -1,4 +1,5 @@
module Kemal::Middleware module Kemal::Middleware
# This middleware adds SSL / TLS support.
class SSL class SSL
getter context getter context

View file

@ -1,3 +1,5 @@
# This is here to represent the logger corresponding to Null Object Pattern. module Kemal
class Kemal::NullLogHandler < Kemal::BaseLogHandler # This is here to represent the logger corresponding to Null Object Pattern.
class NullLogHandler < Kemal::BaseLogHandler
end
end end

View file

@ -1,11 +1,12 @@
require "json" require "json"
# ParamParser parses the request contents including query_params and body module Kemal
# and converts them into a params hash which you can within the environment # ParamParser parses the request contents including query_params and body
# context. # and converts them into a params hash which you can within the environment
alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type) # context.
alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type)
class Kemal::ParamParser class ParamParser
URL_ENCODED_FORM = "application/x-www-form-urlencoded" URL_ENCODED_FORM = "application/x-www-form-urlencoded"
APPLICATION_JSON = "application/json" APPLICATION_JSON = "application/json"
@ -70,4 +71,5 @@ class Kemal::ParamParser
def parse_part(part) def parse_part(part)
HTTP::Params.parse(part || "") HTTP::Params.parse(part || "")
end end
end
end end

View file

@ -1,7 +1,8 @@
# Route is the main building block of Kemal. module Kemal
# It takes 3 parameters: Method, path and a block to specify # Route is the main building block of Kemal.
# what action to be done if the route is matched. # It takes 3 parameters: Method, path and a block to specify
class Kemal::Route # what action to be done if the route is matched.
class Route
getter handler getter handler
@handler : HTTP::Server::Context -> String @handler : HTTP::Server::Context -> String
@method : String @method : String
@ -9,4 +10,5 @@ class Kemal::Route
def initialize(@method, @path : String, &handler : HTTP::Server::Context -> _) def initialize(@method, @path : String, &handler : HTTP::Server::Context -> _)
@handler = ->(context : HTTP::Server::Context) { handler.call(context).to_s } @handler = ->(context : HTTP::Server::Context) { handler.call(context).to_s }
end end
end
end end

View file

@ -1,9 +1,9 @@
require "http/server"
require "radix" require "radix"
# Kemal::RouteHandler is the main handler which handles all the HTTP requests. Routing, parsing, rendering e.g module Kemal
# are done in this handler. # Kemal::RouteHandler is the main handler which handles all the HTTP requests. Routing, parsing, rendering e.g
class Kemal::RouteHandler < HTTP::Handler # are done in this handler.
class RouteHandler < HTTP::Handler
INSTANCE = new INSTANCE = new
property tree property tree
@ -50,4 +50,5 @@ class Kemal::RouteHandler < HTTP::Handler
node = radix_path method, path node = radix_path method, path
@tree.add node, route @tree.add node, route
end end
end
end end

View file

@ -1,11 +1,13 @@
# Kemal::StaticFileHandler is used to serve static files(.js/.css/.png e.g). module Kemal
# This handler is on by default and you can disable it like. # Kemal::StaticFileHandler is used to serve static files(.js/.css/.png e.g).
# # This handler is on by default and you can disable it like.
# serve_static false #
# # serve_static false
class Kemal::StaticFileHandler < HTTP::StaticFileHandler #
class StaticFileHandler < HTTP::StaticFileHandler
def call(context) def call(context)
return call_next(context) if context.request.path.not_nil! == "/" return call_next(context) if context.request.path.not_nil! == "/"
super super
end end
end
end end

View file

@ -1,6 +1,7 @@
# Kemal::WebSocketHandler is used for building a WebSocket route. module Kemal
# For each WebSocket route a new handler is created and registered to global handlers. # Kemal::WebSocketHandler is used for building a WebSocket route.
class Kemal::WebSocketHandler < HTTP::WebSocketHandler # For each WebSocket route a new handler is created and registered to global handlers.
class WebSocketHandler < HTTP::WebSocketHandler
def initialize(@path : String, &@proc : HTTP::WebSocket, HTTP::Server::Context -> Void) def initialize(@path : String, &@proc : HTTP::WebSocket, HTTP::Server::Context -> Void)
Kemal.config.add_ws_handler self Kemal.config.add_ws_handler self
end end
@ -9,4 +10,5 @@ class Kemal::WebSocketHandler < HTTP::WebSocketHandler
return call_next(context) unless context.request.path.not_nil! == @path return call_next(context) unless context.request.path.not_nil! == @path
super super
end end
end
end end