forked from amberframework/amber
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor routing & pipeline dsl (amberframework#17)
* Move Router & Pipeline DSLs under Amber::Support::DSL module * Make the DSLs tied to a particular Router/Pipeline instance * Fix router spec
- Loading branch information
Showing
6 changed files
with
38 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Amber::Support::DSL | ||
record Pipeline, pipeline : Pipe::Pipeline do | ||
def plug(pipe) | ||
pipeline.plug pipe | ||
end | ||
end | ||
|
||
record Router, router : Pipe::Router do | ||
macro route(verb, resource, controller, handler, pipeline) | ||
%ctrl = {{controller.id}}.new | ||
%action = ->%ctrl.{{handler.id}} | ||
%verb = {{verb.upcase.id.stringify}} | ||
%route = Amber::Route.new(%verb, {{resource}}, %ctrl, %action, {{pipeline}}) | ||
|
||
router.add(%route) | ||
end | ||
|
||
{% for verb in {:get, :post, :put, :delete, :options, :head, :trace, :connect} %} | ||
|
||
macro {{verb.id}}(*args) | ||
route {{verb}}, \{{*args}} | ||
end | ||
|
||
{% end %} | ||
end | ||
end |