Guest User

Untitled

a guest
Apr 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. Merb::Router.prepare do |r|
  2. r.resources :posts
  3. r.default_routes
  4. r.match('/').to(:controller => 'whatever', :action =>'index')
  5. end
  6.  
  7.  
  8. will produce this match method:
  9.  
  10. def match(request)
  11. params = request.params
  12. cached_path = request.path
  13. cached_method = request.method.to_s
  14. if # {:path=>"^/posts/?(\\.:format)?$", :method=>"^get$"}
  15. (/^\/posts\/?(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2 = $1, $2) && (/^get$/ =~ cached_method)
  16. # then
  17. [0, {:action => "index", :format => path2, :controller => "posts"}]
  18. elsif # {:path=>"^/posts/index(\\.:format)?$", :method=>"^get$"}
  19. (/^\/posts\/index(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2 = $1, $2) && (/^get$/ =~ cached_method)
  20. # then
  21. [1, {:action => "index", :format => path2, :controller => "posts"}]
  22. elsif # {:path=>"^/posts/new$", :method=>"^get$"}
  23. (/^\/posts\/new$/ =~ cached_path) && (/^get$/ =~ cached_method)
  24. # then
  25. [2, {:action => "new", :controller => "posts"}]
  26. elsif # {:path=>"^/posts/?(\\.:format)?$", :method=>"^post$"}
  27. (/^\/posts\/?(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2 = $1, $2) && (/^post$/ =~ cached_method)
  28. # then
  29. [3, {:action => "create", :format => path2, :controller => "posts"}]
  30. elsif # {:path=>"^/posts/:id(\\.:format)?$", :method=>"^get$"}
  31. (/^\/posts\/([^\/.,;?]+)(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2, path3 = $1, $2, $3) && (/^get$/ =~ cached_method)
  32. # then
  33. [4, {:action => "show", :format => path3, :controller => "posts", :id => path1}]
  34. elsif # {:path=>"^/posts/:id[;/]edit$", :method=>"^get$"}
  35. (/^\/posts\/([^\/.,;?]+)[;\/]edit$/ =~ cached_path) && (path1 = $1) && (/^get$/ =~ cached_method)
  36. # then
  37. [5, {:action => "edit", :controller => "posts", :id => path1}]
  38. elsif # {:path=>"^/posts/:id[;/]delete$", :method=>"^get$"}
  39. (/^\/posts\/([^\/.,;?]+)[;\/]delete$/ =~ cached_path) && (path1 = $1) && (/^get$/ =~ cached_method)
  40. # then
  41. [6, {:action => "delete", :controller => "posts", :id => path1}]
  42. elsif # {:path=>"^/posts/:id(\\.:format)?$", :method=>"^put$"}
  43. (/^\/posts\/([^\/.,;?]+)(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2, path3 = $1, $2, $3) && (/^put$/ =~ cached_method)
  44. # then
  45. [7, {:action => "update", :format => path3, :controller => "posts", :id => path1}]
  46. elsif # {:path=>"^/posts/:id(\\.:format)?$", :method=>"^delete$"}
  47. (/^\/posts\/([^\/.,;?]+)(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2, path3 = $1, $2, $3) && (/^delete$/ =~ cached_method)
  48. # then
  49. [8, {:action => "destroy", :format => path3, :controller => "posts", :id => path1}]
  50. elsif # {:path=>"/:controller(/:action(/:id)?)?(\\.:format)?"}
  51. (/\/([^\/.,;?]+)(\/([^\/.,;?]+)(\/([^\/.,;?]+))?)?(\.([^\/.,;?]+))?/ =~ cached_path) && (path1, path2, path3, path4, path5, path6, path7 = $1, $2, $3, $4, $5, $6, $7)
  52. # then
  53. [9, {:action => path3 || "index", :format => path7, :controller => path1, :id => path5}]
  54. elsif # {:path=>"^/$"}
  55. (/^\/$/ =~ cached_path)
  56. # then
  57. [10, {:action => "index", :controller => "whatever"}]
  58. else
  59. [nil, {}]
  60. end
  61. end
Add Comment
Please, Sign In to add comment