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 it "parses POST body" do
kemal = Kemal::Handler.new kemal = Kemal::Handler.new
kemal.add_route "POST", "/" do |env| kemal.add_route "POST", "/" do |env|
name = env.request.params["name"] name = env.params["name"]
age = env.request.params["age"] age = env.params["age"]
hasan = env.request.params["hasan"] hasan = env.params["hasan"]
"Hello #{name} #{hasan} #{age}" "Hello #{name} #{hasan} #{age}"
end end
request = HTTP::Request.new("POST", "/?hasan=cemal", body: "name=kemal&age=99") request = HTTP::Request.new("POST", "/?hasan=cemal", body: "name=kemal&age=99")

View file

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

View file

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

View file

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

View file

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