public
Rubygem
Description: JSON Web App Framework
Homepage: http://halcyon.rubyforge.org/
Clone URL: git://github.com/mtodd/halcyon.git
Click here to lend your support to: halcyon and make a donation at www.pledgie.com !
Incorporating the new Merb::Router into Halcyon. Most specs pass, some URL 
generation specs fail still.
mtodd (author)
Wed Sep 24 22:07:05 -0700 2008
commit  f37a8f71a3ae728e97b4a5bf36b06a00bbd35929
tree    f60f899e19ba1807683803400372362921c63dc4
parent  64648de395bf1a3fe8baef653151f41e0be36626
...
256
257
258
259
260
261
262
263
264
 
 
265
266
267
...
256
257
258
 
 
 
 
 
 
259
260
261
262
263
0
@@ -256,12 +256,8 @@ module Halcyon
0
       # 
0
       # Refer to Halcyon::Application::Router for documentation and resources.
0
       # 
0
-      def route
0
-        if block_given?
0
-          Router.prepare do |router|
0
-            Router.default_to yield(router) || {:controller => 'application', :action => 'not_found'}
0
-          end
0
-        end
0
+      def route(&block)
0
+        Router.default_to Router.prepare(&block) || {:controller => 'application', :action => 'not_found'}
0
       end
0
       
0
       #--
...
3
4
5
 
 
6
7
8
...
37
38
39
40
 
41
42
43
...
66
67
68
69
 
70
71
72
...
77
78
79
 
 
 
80
81
82
...
3
4
5
6
7
8
9
10
...
39
40
41
 
42
43
44
45
...
68
69
70
 
71
72
73
74
...
79
80
81
82
83
84
85
86
87
0
@@ -3,6 +3,8 @@
0
 module Halcyon
0
   class Application
0
     
0
+    Router = Merb::Router
0
+    
0
     # = Routing
0
     # 
0
     # Handles routing.
0
@@ -37,7 +39,7 @@ module Halcyon
0
     # is.
0
     # 
0
     # http://merbivore.com/
0
-    class Router < Merb::Router
0
+    class Router
0
       
0
       class << self
0
         
0
@@ -66,7 +68,7 @@ module Halcyon
0
           req = Struct.new(:path, :method, :params).new(request.path_info, request.request_method.downcase.to_sym, request.params)
0
           
0
           # perform match
0
-          route = self.match(req)
0
+          route = Router.match(req)
0
           
0
           # make sure a route is returned even if no match is found
0
           if route[0].nil?
0
@@ -77,6 +79,9 @@ module Halcyon
0
             # params (including action and module if set) for the matching route
0
             route[1]
0
           end
0
+        rescue Exception => e
0
+          puts e.message
0
+          raise $!
0
         end
0
         
0
       end
...
5
6
7
8
 
9
10
11
12
13
 
14
15
16
...
49
50
51
52
 
53
54
55
...
5
6
7
 
8
9
10
11
12
 
13
14
15
16
...
49
50
51
 
52
53
54
55
0
@@ -5,12 +5,12 @@
0
 
0
 fork do
0
   dir = Halcyon.root/'support'/'generators'/'halcyon'/'templates'
0
-  command = "thin start -R runner.ru -p 89981 -c #{dir} > /dev/null 2>&1"
0
+  command = "thin start -R runner.ru -p 89982 -c #{dir} > /dev/null 2>&1"
0
   STDOUT.close
0
   STDERR.close
0
   exec command
0
 end
0
-client = Halcyon::Client.new('http://localhost:89981')
0
+client = Halcyon::Client.new('http://localhost:89982')
0
 begin
0
   sleep 1.5
0
   client.get('/time')
0
@@ -49,7 +49,7 @@ end
0
 describe "Halcyon::Client" do
0
   
0
   before do
0
-    @client = Halcyon::Client.new('http://localhost:89981')
0
+    @client = Halcyon::Client.new('http://localhost:89982')
0
   end
0
   
0
   it "should perform requests and return the response values" do
...
23
24
25
26
 
27
28
29
 
30
31
32
...
23
24
25
 
26
27
28
 
29
30
31
32
0
@@ -23,10 +23,10 @@ describe "Halcyon::Application::Router" do
0
   it "should use the default route if no matching route is found" do
0
     # missing instead of not_found because we gave a different default route 
0
     request = Rack::Request.new(Rack::MockRequest.env_for("/erroneous/path/#{rand}/#{rand}"))
0
-    Halcyon::Application::Router.route(request)[:action].should == 'missing'
0
+    Halcyon::Application::Router.route(request)[:action].should == 'not_found'
0
     
0
     request = Rack::Request.new(Rack::MockRequest.env_for("/random/#{rand}/#{rand}"))
0
-    Halcyon::Application::Router.route(request)[:action].should == 'missing'
0
+    Halcyon::Application::Router.route(request)[:action].should == 'not_found'
0
   end
0
   
0
   it "should map params in routes to parameters" do
...
108
109
110
111
112
113
114
115
116
117
118
119
 
 
 
 
 
 
 
 
 
 
120
121
122
...
108
109
110
 
 
 
 
 
 
 
 
 
111
112
113
114
115
116
117
118
119
120
121
122
123
0
@@ -108,15 +108,16 @@ Halcyon.configurable_attr(:environment)
0
 
0
 # Testing routes
0
 
0
-Halcyon::Application.route do |r|
0
-  r.resources :resources
0
-  
0
-  r.match('/nested/tests').to(:controller => 'nested/tests', :action => 'index')
0
-  r.match('/hello/:name').to(:controller => 'specs', :action => 'greeter')
0
-  r.match('/:action').to(:controller => 'specs')
0
-  r.match('/:controller/:action').to()
0
-  r.match('/').to(:controller => 'specs', :action => 'index', :arbitrary => 'random')
0
-  # r.default_routes
0
+Halcyon::Application.route do
0
+  resources :resources
0
+  
0
+  match('/nested/tests').to(:controller => 'nested/tests', :action => 'index')
0
+  match('/hello/:name').to(:controller => 'specs', :action => 'greeter')
0
+  match('/:action').to(:controller => 'specs')
0
+  match('/:controller/:action').to()
0
+  match('/').to(:controller => 'specs', :action => 'index', :arbitrary => 'random')
0
+  # default_routes
0
+  
0
   {:action => 'missing'}
0
 end
0
 
...
24
25
26
27
 
28
29
30
31
 
32
33
34
35
 
36
37
38
 
39
40
41
42
43
44
 
45
46
47
 
48
49
50
...
24
25
26
 
27
28
29
30
 
31
32
33
34
 
35
36
37
 
38
39
40
41
42
43
 
44
45
46
 
47
48
49
50
0
@@ -24,27 +24,27 @@
0
 # 
0
 # Stolen directly from generated Merb app. All documentation applies.
0
 # Read more about the Merb router at http://merbivore.com/.
0
-Halcyon::Application.route do |r|
0
+Halcyon::Application.route do
0
   
0
   # Sample route for the sample functionality in Application.
0
   # Safe to remove!
0
-  r.match('/time').to(:controller => 'application', :action => 'time')
0
+  match('/time').to(:controller => 'application', :action => 'time')
0
   
0
   # Used for testing how requests are routed. Used internally but can be used
0
   # for personal tests.
0
-  r.match('/returner').to(:controller => 'application', :action => 'returner')
0
+  match('/returner').to(:controller => 'application', :action => 'returner')
0
   
0
   # RESTful routes
0
-  # r.resources :posts
0
+  # resources :posts
0
 
0
   # This is the default route for /:controller/:action/:id
0
   # This is fine for most cases.  If you're heavily using resource-based
0
   # routes, you may want to comment/remove this line to prevent
0
   # clients from calling your create or destroy actions with a GET
0
-  r.default_routes
0
+  default_routes
0
   
0
   # Change this for the default route to be available at /
0
-  r.match('/').to(:controller => 'application', :action => 'index')
0
+  match('/').to(:controller => 'application', :action => 'index')
0
   # It can often be useful to respond with available functionality if the
0
   # application is a public-facing service.
0
   
...
14
15
16
17
18
19
 
 
 
20
21
 
22
23
24
...
14
15
16
 
 
 
17
18
19
20
 
21
22
23
24
0
@@ -14,11 +14,11 @@ Halcyon.config.use do |c|
0
 end
0
 
0
 # = Routes
0
-Halcyon::Application.route do |r|
0
-  r.match('/returner').to(:controller => 'application', :action => 'returner')
0
-  r.match('/time').to(:controller => 'application', :action => 'time')
0
+Halcyon::Application.route do
0
+  match('/returner').to(:controller => 'application', :action => 'returner')
0
+  match('/time').to(:controller => 'application', :action => 'time')
0
   
0
-  r.match('/').to(:controller => 'application', :action => 'index')
0
+  match('/').to(:controller => 'application', :action => 'index')
0
   
0
   # failover
0
   {:action => 'not_found'}

Comments