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

View file

@ -1,11 +1,12 @@
require "json"
# 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)
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"
@ -70,4 +71,5 @@ class Kemal::ParamParser
def parse_part(part)
HTTP::Params.parse(part || "")
end
end
end

View file

@ -1,7 +1,8 @@
# 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
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 Route
getter handler
@handler : HTTP::Server::Context -> String
@method : String
@ -9,4 +10,5 @@ class Kemal::Route
def initialize(@method, @path : String, &handler : HTTP::Server::Context -> _)
@handler = ->(context : HTTP::Server::Context) { handler.call(context).to_s }
end
end
end

View file

@ -1,9 +1,9 @@
require "http/server"
require "radix"
# 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
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 RouteHandler < HTTP::Handler
INSTANCE = new
property tree
@ -50,4 +50,5 @@ class Kemal::RouteHandler < HTTP::Handler
node = radix_path method, path
@tree.add node, route
end
end
end

View file

@ -1,11 +1,13 @@
# 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
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 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 @@
# 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
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 WebSocketHandler < HTTP::WebSocketHandler
def initialize(@path : String, &@proc : HTTP::WebSocket, HTTP::Server::Context -> Void)
Kemal.config.add_ws_handler self
end
@ -9,4 +10,5 @@ class Kemal::WebSocketHandler < HTTP::WebSocketHandler
return call_next(context) unless context.request.path.not_nil! == @path
super
end
end
end