-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor routing & pipeline dsl #17
Conversation
@@ -6,7 +6,7 @@ module Amber | |||
describe "#call" do | |||
it "raises exception when route not found" do | |||
router = Router.instance | |||
request = HTTP::Request.new("GET", "/hello/world") | |||
request = HTTP::Request.new("GET", "/bad/route") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/amber/pipe/pipeline.cr
Outdated
with PipelineDSL.new(self) yield | ||
end | ||
|
||
record PipelineDSL, pipeline : Pipeline do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to learn more about Records this is very nice and clean. I see what you meant about using singletons
src/amber/pipe/router.cr
Outdated
@@ -61,6 +61,27 @@ module Amber | |||
trail = build_node(:HEAD, route.resource) | |||
@routes.add(trail, route) | |||
end | |||
|
|||
record RouterDSL, router : Router do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great cleanup! 🎉 I wanted to do something similar but didn't knew how to use macros
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great cleanup and learn a lot from the refactor. Good work @bew 👍
Maybe we should consider moving all the DSLs into Amber::Support::DSL module? to keep it organize? |
Why not, what is Amber::Support exactly for you? |
Amber::Support should host all of our custom stuff specific to the framework: DSL, Extensions, Modules etc |
This starts decoupling singletons from everywhere.
bcef853
to
e833a8b
Compare
* Move Router & Pipeline DSLs under Amber::Support::DSL module * Make the DSLs tied to a particular Router/Pipeline instance * Fix router spec
* Move Router & Pipeline DSLs under Amber::Support::DSL module * Make the DSLs tied to a particular Router/Pipeline instance * Fix router spec
* Move Router & Pipeline DSLs under Amber::Support::DSL module * Make the DSLs tied to a particular Router/Pipeline instance * Fix router spec
Description of the Change
This PR moves the pipeline and routes DSLs inside Amber module, in the revelant classes.
DSL
stands for Domain Specific Language. Here we have 2 distinct DSLs:plug
)get
,post
, ...)Why Should This Be In Core?
Before theses changes, the 2 DSLs where exposed in the top level and where only macros, which could potentially break every program that includes them (see crystal-lang/crystal#236).
Benefits
plug
inpipeline
for example).