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,3 +1,4 @@
module Kemal
# All loggers must inherit from `Kemal::BaseLogHandler`.
class Kemal::BaseLogHandler < HTTP::Handler
def initialize
@ -10,3 +11,4 @@ class Kemal::BaseLogHandler < HTTP::Handler
def write(message)
end
end
end

View file

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

View file

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

View file

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

View file

@ -1,11 +1,12 @@
require "json"
module Kemal
# ParamParser parses the request contents including query_params and body
# and converts them into a params hash which you can within the environment
# 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"
APPLICATION_JSON = "application/json"
@ -71,3 +72,4 @@ class Kemal::ParamParser
HTTP::Params.parse(part || "")
end
end
end

View file

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

View file

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

View file

@ -1,11 +1,13 @@
module Kemal
# 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
#
class Kemal::StaticFileHandler < HTTP::StaticFileHandler
class StaticFileHandler < HTTP::StaticFileHandler
def call(context)
return call_next(context) if context.request.path.not_nil! == "/"
super
end
end
end

View file

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