Removing redundant code

This commit is contained in:
Sdogruyol 2015-10-28 18:09:45 +02:00
parent 4c0dd927ee
commit a8ad95aa67
5 changed files with 10 additions and 18 deletions

View file

@ -54,9 +54,9 @@ describe "Kemal::Handler" do
it "parses POST body" do
kemal = Kemal::Handler.new
kemal.add_route "POST", "/" do |env|
name = env.request.params["name"]
age = env.request.params["age"]
hasan = env.request.params["hasan"]
name = env.params["name"]
age = env.params["age"]
hasan = env.params["hasan"]
"Hello #{name} #{hasan} #{age}"
end
request = HTTP::Request.new("POST", "/?hasan=cemal", body: "name=kemal&age=99")

View file

@ -1,7 +1,8 @@
class Kemal::Context
getter request
getter params
def initialize(@request)
def initialize(@request, @params)
end
def response
@ -11,8 +12,4 @@ class Kemal::Context
def response?
@response
end
def params
request.params
end
end

View file

@ -34,8 +34,7 @@ class Kemal::Handler < HTTP::Handler
end
end
kemal_request = Request.new(request, params)
context = Context.new(kemal_request)
context = Context.new(request, params)
begin
body = route.handler.call(context).to_s
content_type = context.response?.try(&.content_type) || "text/plain"

View file

@ -8,4 +8,8 @@ class Kemal::Logger
@stream.puts message
end
{% end %}
def exception(e)
error "#{e.message}:\n\t#{e.backtrace.join("\n\t")}"
end
end

View file

@ -1,8 +0,0 @@
class Kemal::Request
getter params
def initialize(@request, @params)
end
delegate body, @request
end