Skip to content
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

Merged
merged 5 commits into from
Apr 23, 2017
Merged

Conversation

bew
Copy link
Contributor

@bew bew commented Apr 23, 2017

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:

  • Pipeline (with plug)
  • Routing (with 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

  • The DSLs are only available inside specific blocks (plug in pipeline for example).
  • They apply changes to a specific router/pipeline (no singleton involved here!)

@bew bew requested a review from eliasjpr April 23, 2017 02:58
@@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

with PipelineDSL.new(self) yield
end

record PipelineDSL, pipeline : Pipeline do
Copy link
Contributor

@eliasjpr eliasjpr Apr 23, 2017

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

@@ -61,6 +61,27 @@ module Amber
trail = build_node(:HEAD, route.resource)
@routes.add(trail, route)
end

record RouterDSL, router : Router do
Copy link
Contributor

@eliasjpr eliasjpr Apr 23, 2017

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

Copy link
Contributor

@eliasjpr eliasjpr left a 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 👍

@eliasjpr
Copy link
Contributor

Maybe we should consider moving all the DSLs into Amber::Support::DSL module? to keep it organize?

@bew
Copy link
Contributor Author

bew commented Apr 23, 2017

Why not, what is Amber::Support exactly for you?

@eliasjpr
Copy link
Contributor

Amber::Support should host all of our custom stuff specific to the framework: DSL, Extensions, Modules etc

@bew bew force-pushed the refactor-routing-pipeline-dsl branch from bcef853 to e833a8b Compare April 23, 2017 15:40
@bew bew merged commit 181fcc6 into master Apr 23, 2017
@bew bew deleted the refactor-routing-pipeline-dsl branch April 23, 2017 15:43
eliasjpr pushed a commit that referenced this pull request Apr 26, 2017
* Move Router & Pipeline DSLs under Amber::Support::DSL module
* Make the DSLs tied to a particular Router/Pipeline instance
* Fix router spec
@eliasjpr eliasjpr mentioned this pull request May 20, 2017
elorest pushed a commit that referenced this pull request Aug 26, 2017
elorest pushed a commit that referenced this pull request Aug 26, 2017
marksiemers pushed a commit to marksiemers/amber that referenced this pull request Oct 28, 2017
* Move Router & Pipeline DSLs under Amber::Support::DSL module
* Make the DSLs tied to a particular Router/Pipeline instance
* Fix router spec
elorest pushed a commit that referenced this pull request Nov 17, 2017
* Move Router & Pipeline DSLs under Amber::Support::DSL module
* Make the DSLs tied to a particular Router/Pipeline instance
* Fix router spec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants