r.match extra syntactical ugliness
Reported by Ben Nevile | May 13th, 2008 @ 11:16 PM | in 0.9.4
here's what I currently have to do:
r.match('/fb/:callback_path/:controller/:action').to({})
here's what I would like to be able to do:
r.match('/fb/:callback_path/:controller/:action')
Comments and changes to this ticket
-
Michael Klishin (antares) May 15th, 2008 @ 12:04 AM
- → Assigned user changed from to Michael Klishin (antares)
- → Milestone changed from to 0.9.4
- → State changed from new to open
It is classic DSL "when to finish" problem. to method you call actually registers new route.
Martin Fowler in his WIP on DSL book wrote that a good way to tackle this is just to have finalization method. Could you think of a good name for that?
-
Ben Nevile May 15th, 2008 @ 12:56 AM
finalization method -- you mean as in the classic sense, one that is called by the garbage collector? Or do you mean a method that's called after all Behaviors have been created, that would iterate through and create routes for all those that hadn't yet created one? I'm not fond of that pattern, but it works.
I was thinking more along the lines of a refactorization so that a new Behavior creates a default route that is subsequently replaced if a to method is called. After a superficial scan of the code it looks like Behavior::to_route would have to be modified to
1. store any route it creates in a local attribute,
2. replace the route if called again.
Also,
3. Behavior::initialize would also have to call to_route with whatever params it has upon creation.
Again, I have only looked at this code briefly, so apols if this is overlooking anything basic.
-
Michael Klishin (antares) May 15th, 2008 @ 07:26 AM
See Stopping problem
Router DSL uses this technique pretty heavily.
-
Ben Nevile May 15th, 2008 @ 09:46 AM
So the text you referred me to above recommends using a pattern more like this:
*** ruby
r.to(match('/fb/:callback_path/:controller/:action'))
***
-
Michael Klishin (antares) May 15th, 2008 @ 10:03 AM
Given existing syntax that won't change (probability at this point is well over 90%), we need to add "finalizing" method that constructs routes without explicit parameters (what to({}) does), like thind:
r.match("/:callback_path/:controller/:action").done!
What do you think is a good name for that?
-
Michael Klishin (antares) May 16th, 2008 @ 12:30 AM
Probably will be implemented as part of updates introduced by #321.
-
coryodaniel(midget_nuts|codaniel) May 16th, 2008 @ 03:04 AM
High five. This makes r.match(whatever).fixatable awesome...
I was tired of
r.match("/mypath").to("/mypath").fixatable
-
coryodaniel(midget_nuts|codaniel) May 16th, 2008 @ 04:45 AM
For the finalizer name why not:
r.match!("/myroute")
Just have #match! Call #match and do the .to()
-
Star Trader May 16th, 2008 @ 04:59 AM
I personally like corydaniel's solution, it seems the cleanest. I'm working on a patch in the same area (c.f. ticket 324) and could easily do this in while I have the code in my head. None of these solutions are difficult, but we are facing a rapidly approaching API freeze deadline. Can we get a decision from the maintainers as to how to make this work?
-
Michael Klishin (antares) May 16th, 2008 @ 03:08 PM
This match! thing should be easy to implement and I really like it. I sent email to Merb mailing list to get some more
comments because we have some racing conditions between people who would like work on different router improvements.
-
-
-
Michael Klishin (antares) May 17th, 2008 @ 01:08 AM
- → State changed from open to resolved
Pushed, thank you.
-
coryodaniel(midget_nuts|codaniel) May 18th, 2008 @ 05:01 AM
No problem any time you guys need a !, just let me know. I have plenty!!!!11!1eleven!!!
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
