From f92d812c32acb1fa3efb84baff3ed9c280ad4ce2 Mon Sep 17 00:00:00 2001 From: sdogruyol Date: Wed, 15 Jun 2016 08:58:14 +0300 Subject: [PATCH] Format --- src/kemal/cli.cr | 1 - src/kemal/context.cr | 2 +- src/kemal/exceptions.cr | 3 +-- src/kemal/middleware/filters.cr | 6 +++--- src/kemal/param_parser.cr | 6 +++--- src/kemal/route_handler.cr | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/kemal/cli.cr b/src/kemal/cli.cr index ef873b3..5319edb 100644 --- a/src/kemal/cli.cr +++ b/src/kemal/cli.cr @@ -3,7 +3,6 @@ require "option_parser" module Kemal # Handles all the initialization from the command line. class CLI - def initialize @ssl_enabled = false @key_file = "" diff --git a/src/kemal/context.cr b/src/kemal/context.cr index d522262..f1c7023 100644 --- a/src/kemal/context.cr +++ b/src/kemal/context.cr @@ -13,7 +13,7 @@ class HTTP::Server end def route_lookup - Kemal::RouteHandler::INSTANCE.lookup_route(@request.override_method as String, @request.path) + Kemal::RouteHandler::INSTANCE.lookup_route(@request.override_method.as(String), @request.path) end def route_defined? diff --git a/src/kemal/exceptions.cr b/src/kemal/exceptions.cr index 4e641f5..83c2753 100644 --- a/src/kemal/exceptions.cr +++ b/src/kemal/exceptions.cr @@ -1,12 +1,11 @@ module Kemal::Exceptions class RouteNotFound < Exception def initialize(context) - super "Requested path: '#{context.request.override_method as String}:#{context.request.path}' was not found." + super "Requested path: '#{context.request.override_method.as(String)}:#{context.request.path}' was not found." end end class CustomException < Exception - def initialize(context) super "Rendered error with #{context.response.status_code}" end diff --git a/src/kemal/middleware/filters.cr b/src/kemal/middleware/filters.cr index c4c7491..ccf5d95 100644 --- a/src/kemal/middleware/filters.cr +++ b/src/kemal/middleware/filters.cr @@ -29,7 +29,7 @@ module Kemal::Middleware def _add_route_filter(verb, path, type, &block : HTTP::Server::Context -> _) lookup = lookup_filters_for_path_type(verb, path, type) if lookup.found? && lookup.payload.is_a?(Array(Block)) - (lookup.payload as Array(Block)) << Block.new(&block) + (lookup.payload.as(Array(Block))) << Block.new(&block) else @tree.add radix_path(verb, path, type), [Block.new(&block)] end @@ -49,7 +49,7 @@ module Kemal::Middleware private def call_block_for_path_type(verb, path, type, context) lookup = lookup_filters_for_path_type(verb, path, type) if lookup.found? && lookup.payload.is_a? Array(Block) - blocks = lookup.payload as Array(Block) + blocks = lookup.payload.as(Array(Block)) blocks.each { |block| block.call(context) } end end @@ -74,7 +74,7 @@ module Kemal::Middleware property block : HTTP::Server::Context -> String def initialize(&block : HTTP::Server::Context -> _) - @block = ->(context : HTTP::Server::Context) { block.call(context).to_s} + @block = ->(context : HTTP::Server::Context) { block.call(context).to_s } end def call(context) diff --git a/src/kemal/param_parser.cr b/src/kemal/param_parser.cr index d3a428c..1d2aebe 100644 --- a/src/kemal/param_parser.cr +++ b/src/kemal/param_parser.cr @@ -44,7 +44,7 @@ class Kemal::ParamParser def parse_url if params = @request.url_params params.each do |key, value| - @url[key as String] = value as String + @url[key.as(String)] = value.as(String) end end end @@ -56,11 +56,11 @@ class Kemal::ParamParser def parse_json return unless @request.body && @request.headers["Content-Type"]? == APPLICATION_JSON - body = @request.body as String + body = @request.body.as(String) case json = JSON.parse(body).raw when Hash json.each do |key, value| - @json[key as String] = value as AllParamTypes + @json[key.as(String)] = value.as(AllParamTypes) end when Array @json["_json"] = json diff --git a/src/kemal/route_handler.cr b/src/kemal/route_handler.cr index cd45c4e..66196fa 100644 --- a/src/kemal/route_handler.cr +++ b/src/kemal/route_handler.cr @@ -32,7 +32,7 @@ class Kemal::RouteHandler < HTTP::Handler # Processes the route if it's a match. Otherwise renders 404. def process_request(context) raise Kemal::Exceptions::RouteNotFound.new(context) unless context.route_defined? - route = context.route_lookup.payload as Route + route = context.route_lookup.payload.as(Route) content = route.handler.call(context) if Kemal.config.error_handlers.has_key?(context.response.status_code) raise Kemal::Exceptions::CustomException.new(context)