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`. # All loggers must inherit from `Kemal::BaseLogHandler`.
class Kemal::BaseLogHandler < HTTP::Handler class Kemal::BaseLogHandler < HTTP::Handler
def initialize def initialize
@ -10,3 +11,4 @@ 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
@ -31,3 +32,4 @@ 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 @@
module Kemal
# This is here to represent the logger corresponding to Null Object Pattern. # This is here to represent the logger corresponding to Null Object Pattern.
class Kemal::NullLogHandler < Kemal::BaseLogHandler class NullLogHandler < Kemal::BaseLogHandler
end
end end

View file

@ -1,11 +1,12 @@
require "json" require "json"
module Kemal
# ParamParser parses the request contents including query_params and body # ParamParser parses the request contents including query_params and body
# and converts them into a params hash which you can within the environment # and converts them into a params hash which you can within the environment
# context. # context.
alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type) 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"
@ -71,3 +72,4 @@ class Kemal::ParamParser
HTTP::Params.parse(part || "") HTTP::Params.parse(part || "")
end end
end end
end

View file

@ -1,7 +1,8 @@
module Kemal
# Route is the main building block of Kemal. # Route is the main building block of Kemal.
# It takes 3 parameters: Method, path and a block to specify # It takes 3 parameters: Method, path and a block to specify
# what action to be done if the route is matched. # what action to be done if the route is matched.
class Kemal::Route class Route
getter handler getter handler
@handler : HTTP::Server::Context -> String @handler : HTTP::Server::Context -> String
@method : String @method : String
@ -10,3 +11,4 @@ class Kemal::Route
@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"
module Kemal
# Kemal::RouteHandler is the main handler which handles all the HTTP requests. Routing, parsing, rendering e.g # Kemal::RouteHandler is the main handler which handles all the HTTP requests. Routing, parsing, rendering e.g
# are done in this handler. # are done in this handler.
class Kemal::RouteHandler < HTTP::Handler class RouteHandler < HTTP::Handler
INSTANCE = new INSTANCE = new
property tree property tree
@ -51,3 +51,4 @@ class Kemal::RouteHandler < HTTP::Handler
@tree.add node, route @tree.add node, route
end end
end end
end

View file

@ -1,11 +1,13 @@
module Kemal
# Kemal::StaticFileHandler is used to serve static files(.js/.css/.png e.g). # 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. # 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 @@
module Kemal
# Kemal::WebSocketHandler is used for building a WebSocket route. # Kemal::WebSocketHandler is used for building a WebSocket route.
# For each WebSocket route a new handler is created and registered to global handlers. # 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) 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
@ -10,3 +11,4 @@ class Kemal::WebSocketHandler < HTTP::WebSocketHandler
super super
end end
end end
end