Add add_handler macro
This commit is contained in:
parent
6a4ed2d9eb
commit
eb4c82043a
4 changed files with 18 additions and 7 deletions
|
@ -1,11 +1,5 @@
|
||||||
require "./spec_helper"
|
require "./spec_helper"
|
||||||
|
|
||||||
class CustomTestHandler < HTTP::Handler
|
|
||||||
def call(request)
|
|
||||||
call_next request
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Config" do
|
describe "Config" do
|
||||||
it "sets default port to 3000" do
|
it "sets default port to 3000" do
|
||||||
config = Kemal.config
|
config = Kemal.config
|
||||||
|
|
|
@ -14,4 +14,11 @@ describe "Macros" do
|
||||||
Kemal.config.public_folder.should eq("/some/path/to/folder")
|
Kemal.config.public_folder.should eq("/some/path/to/folder")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#add_handler" do
|
||||||
|
it "adds a custom handler" do
|
||||||
|
add_handler CustomTestHandler.new
|
||||||
|
Kemal.config.handlers.size.should eq 1
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,12 @@ require "../src/kemal/middleware/*"
|
||||||
|
|
||||||
include Kemal
|
include Kemal
|
||||||
|
|
||||||
|
class CustomTestHandler < HTTP::Handler
|
||||||
|
def call(request)
|
||||||
|
call_next request
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Spec.before_each do
|
Spec.before_each do
|
||||||
Kemal.config.env = "development"
|
Kemal.config.env = "development"
|
||||||
Kemal.config.handlers.clear
|
Kemal.config.handlers.clear
|
||||||
|
|
|
@ -21,10 +21,14 @@ macro redirect(url)
|
||||||
env.response.status_code = 301
|
env.response.status_code = 301
|
||||||
end
|
end
|
||||||
|
|
||||||
|
macro add_handler(handler)
|
||||||
|
Kemal.config.add_handler {{handler}}
|
||||||
|
end
|
||||||
|
|
||||||
# Uses Kemal::Middleware::HTTPBasicAuth to easily add HTTP Basic Auth support.
|
# Uses Kemal::Middleware::HTTPBasicAuth to easily add HTTP Basic Auth support.
|
||||||
macro basic_auth(username, password)
|
macro basic_auth(username, password)
|
||||||
auth_handler = Kemal::Middleware::HTTPBasicAuth.new({{username}}, {{password}})
|
auth_handler = Kemal::Middleware::HTTPBasicAuth.new({{username}}, {{password}})
|
||||||
Kemal.config.add_handler auth_handler
|
add_handler auth_handler
|
||||||
end
|
end
|
||||||
|
|
||||||
macro public_folder(path)
|
macro public_folder(path)
|
||||||
|
|
Loading…
Reference in a new issue