public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Search Repo:
Implemented Merb::Router::Behavior#match! that is a shortcut for 
match(...).to({}).

See #321 for details, background and so forth. Now you can do just

  r.match!("/api/:token/:controller/:action")

and it creates route right away, no need to merge empty params hash
with #to method.

[#321 state:resolved]
Michael S. Klishin (author)
Fri May 16 15:04:21 -0700 2008
commit  56f5c097e66722e2f47f3ad7b77e01799d507d19
tree    4b2b78570396e23d1dc540414ee2badc8f622dc0
parent  c955b78a2881265e296d0be9359a80c4cc05e5c7
...
176
177
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
180
181
...
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
0
@@ -176,6 +176,22 @@
0
         Route.new compiled_conditions, compiled_params, self, &conditional_block
0
       end
0
 
0
+ # Combines common case of match being used with
0
+ # to({}).
0
+ #
0
+ # ==== Returns
0
+ # <Route>:: route that uses params from named path segments.
0
+ #
0
+ # ==== Examples
0
+ # r.match!("/api/:token/:controller/:action/:id")
0
+ #
0
+ # is the same thing as
0
+ #
0
+ # r.match!("/api/:token/:controller/:action/:id").to({})
0
+ def match!(path = '', conditions = {}, &block)
0
+ self.match(path, conditions, &block).to({})
0
+ end
0
+
0
       # Creates a Route from one or more Behavior objects, unless a +block+ is
0
       # passed in.
0
       #
...
1
2
3
4
 
5
6
 
7
8
9
...
11
12
13
14
 
15
16
17
...
21
22
23
24
 
25
26
27
28
...
30
31
32
33
 
34
35
36
37
38
 
39
40
41
...
44
45
46
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
...
1
2
3
 
4
5
 
6
7
8
9
...
11
12
13
 
14
15
16
17
...
21
22
23
 
24
25
26
27
28
...
30
31
32
 
33
34
35
36
37
 
38
39
40
41
...
44
45
46
 
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
0
@@ -1,9 +1,9 @@
0
 require File.join(File.dirname(__FILE__), "spec_helper")
0
 
0
 describe "Regex-based routes" do
0
-
0
+
0
   it "should process a simple regex" do
0
- prepare_route(%r[^/foos?/(bar|baz)/:id], :controller => "foo", :action => "[1]", :id => ":id")
0
+ prepare_route(%r[^/foos?/(bar|baz)/:id], :controller => "foo", :action => "[1]", :id => ":id")
0
     route_to("/foo/bar/baz").should have_route(:controller => "foo", :action => "bar", :id => "baz")
0
     route_to("/foos/baz/bam").should have_route(:controller => "foo", :action => "baz", :id => "bam")
0
   end
0
@@ -11,7 +11,7 @@
0
   it "should support inbound user agents" do
0
     Merb::Router.prepare do |r|
0
       r.match(%r[^/foo/(.+)], :user_agent => /(MSIE|Gecko)/).
0
- to(:controller => "foo", :title => "[1]", :action => "show", :agent => ":user_agent[1]")
0
+ to(:controller => "foo", :title => "[1]", :action => "show", :agent => ":user_agent[1]")
0
     end
0
     route_to("/foo/bar", :user_agent => /MSIE/).should have_route(
0
       :controller => "foo", :action => "show", :title => "bar", :agent => "MSIE"
0
@@ -21,7 +21,7 @@
0
 end
0
 
0
 describe "Routes that are restricted based on incoming params" do
0
-
0
+
0
   it "should allow you to restrict routes to POST requests" do
0
     Merb::Router.prepare do |r|
0
       r.match("/:controller/create/:id", :method => :post).
0
0
@@ -30,12 +30,12 @@
0
     route_to("/foo/create/12", :method => "post").should have_route(
0
       :controller => "foo", :action => "create", :id => "12"
0
     )
0
-
0
+
0
     route_to("/foo/create/12", :method => "get").should_not have_route(
0
       :controller => "foo", :action => "create", :id => "12"
0
     )
0
   end
0
-
0
+
0
   it "should allow you to restrict routes based on protocol" do
0
     Merb::Router.prepare do |r|
0
       r.match(:protocol => "http://").to(:controller => "foo", :action => "bar")
0
@@ -44,6 +44,19 @@
0
     route_to("/foo/bar").should have_route(:controller => "foo", :action => "bar")
0
     route_to("/boo/hoo", :protocol => "https://").should have_route(:controller => "boo", :action => "hoo")
0
   end
0
-
0
+
0
+ it "does not require explicit specifying of params" do
0
+ Merb::Router.prepare do |r|
0
+ r.match!("/fb/:callback_path/:controller/:action")
0
+ end
0
+
0
+ route_to("/fb/callybacky/products/search").should have_route(
0
+ :controller => "products", :action => "search", :callback_path => "callybacky"
0
+ )
0
+ route_to("/fb/ping/products/search").should have_route(
0
+ :controller => "products", :action => "search", :callback_path => "ping"
0
+ )
0
+ end
0
+
0
 end

Comments

    No one has commented yet.