From d676b559d2ed1486545dbdf061c5a0fa6e69c082 Mon Sep 17 00:00:00 2001 From: sdogruyol Date: Tue, 1 Nov 2016 11:46:13 +0300 Subject: [PATCH] Rename return_with as halt for clear intention --- CHANGELOG.md | 2 ++ spec/helpers_spec.cr | 10 +++++----- src/kemal/helpers/macros.cr | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3136729..88cc74f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ Which is illustrated as, Request -> Middleware -> Filter -> Route ``` +- Rename `return_with` as `halt`. + # 0.16.1 (12-10-2016) - Improved Multipart support with more info on parsed files. `parse_multipart(env)` now yields diff --git a/spec/helpers_spec.cr b/spec/helpers_spec.cr index d2b80fa..a1c277e 100644 --- a/spec/helpers_spec.cr +++ b/spec/helpers_spec.cr @@ -35,8 +35,8 @@ describe "Macros" do end end - describe "#return_with" do - it "can break block with return_with macro" do + describe "#halt" do + it "can break block with halt macro" do get "/non-breaking" do |env| "hello" "world" @@ -47,7 +47,7 @@ describe "Macros" do client_response.body.should eq("world") get "/breaking" do |env| - return_with env, 404, "hello" + halt env, 404, "hello" "world" end request = HTTP::Request.new("GET", "/breaking") @@ -56,9 +56,9 @@ describe "Macros" do client_response.body.should eq("hello") end - it "can break block with return_with macro using default values" do + it "can break block with halt macro using default values" do get "/" do |env| - return_with env + halt env "world" end request = HTTP::Request.new("GET", "/") diff --git a/src/kemal/helpers/macros.cr b/src/kemal/helpers/macros.cr index c1105b3..aee49d3 100644 --- a/src/kemal/helpers/macros.cr +++ b/src/kemal/helpers/macros.cr @@ -69,8 +69,8 @@ end # Halt execution with the current context. # Returns 200 and an empty response by default. # -# return_with env, status_code: 403, response: "Forbidden" -macro return_with(env, status_code = 200, response = "") +# halt env, status_code: 403, response: "Forbidden" +macro halt(env, status_code = 200, response = "") {{env}}.response.status_code = {{status_code}} {{env}}.response.print {{response}} next