Switch routing logic to use modules (#2298)

* Switch routing logic to use modules
* Add more macros for adding routes of different HTTP methods
This commit is contained in:
syeopite
2021-08-11 03:36:25 -07:00
committed by GitHub
parent 637a5cc14f
commit 7afa027b95
10 changed files with 52 additions and 58 deletions

View File

@@ -1,15 +1,11 @@
module Invidious::Routing
macro get(path, controller, method = :handle)
get {{ path }} do |env|
controller_instance = {{ controller }}.new
controller_instance.{{ method.id }}(env)
end
end
{% for http_method in {"get", "post", "delete", "options", "patch", "put", "head"} %}
macro post(path, controller, method = :handle)
post {{ path }} do |env|
controller_instance = {{ controller }}.new
controller_instance.{{ method.id }}(env)
macro {{http_method.id}}(path, controller, method = :handle)
{{http_method.id}} \{{ path }} do |env|
\{{ controller }}.\{{ method.id }}(env)
end
end
end
{% end %}
end