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 !
Updated dependencies to use Merb 0.9.2's router et al.
Improved how parsing the route is done (slight improvement in memory 
usage).
Restructured the Router subclass slightly to better match new style.
Polished logging format slightly.
mtodd (author)
Tue Mar 25 02:03:02 -0700 2008
commit  0543566fb3c463d471bff60521e90b36efbbcdc0
tree    28bf3dec9d0af1d7ddfeb6a3fc8175d6d848833f
parent  d0341ba828c1a6325340944fdca79c644fb58861
...
27
28
29
30
 
31
32
33
...
27
28
29
 
30
31
32
33
0
@@ -27,7 +27,7 @@ project = {
0
   :dependencies => {
0
     'json_pure' => '>=1.1.2',
0
     'rack' => '>=0.3.0',
0
- 'merb' => '>=0.4.1',
0
+ 'merb' => '>=0.9.2',
0
     'rubigen' => '>=1.2.4'
0
   },
0
   :requirements => 'install the json gem to get faster JSON parsing',
...
6
7
8
9
 
10
11
12
...
6
7
8
 
9
10
11
12
0
@@ -6,7 +6,7 @@
0
 
0
 $:.unshift File.dirname(__FILE__)
0
 
0
-%w(rubygems rack merb/core_ext merb/router json uri logger).each {|dep|require dep}
0
+%w(rubygems rack merb-core/core_ext merb-core/dispatch/router json uri logger).each {|dep|require dep}
0
 
0
 module Halcyon
0
   
...
50
51
52
53
 
54
55
56
...
50
51
52
 
53
54
55
56
0
@@ -50,7 +50,7 @@ module Halcyon
0
       begin
0
         acceptable_request! env
0
         
0
- env['halcyon.route'] = Router.route(env)
0
+ env['halcyon.route'] = Router.route(request)
0
         result = dispatch(env)
0
       rescue Exceptions::Base => e
0
         result = {:status => e.status, :body => e.body}
...
8
9
10
11
 
12
13
14
...
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
 
81
82
83
84
85
 
 
 
86
87
88
 
 
 
 
 
 
 
 
 
 
89
90
91
92
93
94
95
96
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
100
101
...
8
9
10
 
11
12
13
14
...
59
60
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
63
 
 
 
 
64
65
66
67
 
 
68
69
70
71
72
73
74
75
76
77
78
 
 
 
 
 
 
 
 
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
0
@@ -8,7 +8,7 @@
0
 #++
0
 
0
 begin
0
- %w(rubygems merb/core_ext merb/router uri).each {|dep|require dep}
0
+ %w(rubygems merb-core/core_ext merb-core/dispatch/router uri).each {|dep|require dep}
0
 rescue LoadError => e
0
   abort "Merb must be installed for Routing to function. Please install Merb."
0
 end
0
@@ -59,43 +59,44 @@ module Halcyon
0
     # http://merbivore.com/
0
     class Router < Merb::Router
0
       
0
- # Retrieves the last value from the +route+ call in Halcyon::Server::Base
0
- # and, if it's a Hash, sets it to +@@default_route+ to designate the
0
- # failover route. If +route+ is not a Hash, though, the internal default
0
- # should be used instead (as the last returned value is probably a Route
0
- # object returned by the +r.match().to()+ call).
0
- #
0
- # Used exclusively internally.
0
- def self.default_to route
0
- @@default_route = route.is_a?(Hash) ? route : {:action => 'not_found'}
0
- end
0
-
0
- # Called internally by the Halcyon::Server::Base#call method to match
0
- # the current request against the currently defined routes. Returns the
0
- # params list defined in the +to+ routing definition, opting for the
0
- # default route if no match is made.
0
- def self.route(env)
0
- # pull out the path requested (WEBrick keeps the host and port and protocol in REQUEST_URI)
0
- # PATH_INFO is failover if REQUEST_URI is blank (like what Rack::MockRequest does)
0
- uri = URI.parse(env['REQUEST_URI'] || env['PATH_INFO']).path
0
+ class << self
0
         
0
- # prepare request
0
- path = (uri ? uri.split('?').first : '').sub(/\/+/, '/')
0
- path = path[0..-2] if (path[-1] == ?/) && path.size > 1
0
- req = Struct.new(:path, :method).new(path, env['REQUEST_METHOD'].downcase.to_sym)
0
+ def logger
0
+ Halcyon.logger
0
+ end
0
         
0
- # perform match
0
- route = self.match(req, {})
0
+ # Retrieves the last value from the +route+ call in Halcyon::Server::Base
0
+ # and, if it's a Hash, sets it to +@@default_route+ to designate the
0
+ # failover route. If +route+ is not a Hash, though, the internal default
0
+ # should be used instead (as the last returned value is probably a Route
0
+ # object returned by the +r.match().to()+ call).
0
+ #
0
+ # Used exclusively internally.
0
+ def default_to route
0
+ @@default_route = route.is_a?(Hash) ? route : {:action => 'not_found'}
0
+ end
0
         
0
- # make sure a route is returned even if no match is found
0
- if route[0].nil?
0
- #return default route
0
- env['halcyon.logger'].debug "No route found. Using default." if env['halcyon.logger'].is_a? Logger
0
- @@default_route
0
- else
0
- # params (including action and module if set) for the matching route
0
- route[1]
0
+ # Called internally by the Halcyon::Server::Base#call method to match
0
+ # the current request against the currently defined routes. Returns the
0
+ # params list defined in the +to+ routing definition, opting for the
0
+ # default route if no match is made.
0
+ def route(request)
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
+
0
+ # make sure a route is returned even if no match is found
0
+ if route[0].nil?
0
+ #return default route
0
+ self.logger.debug "No route found. Using default."
0
+ @@default_route
0
+ else
0
+ # params (including action and module if set) for the matching route
0
+ route[1]
0
+ end
0
         end
0
+
0
       end
0
       
0
     end
...
23
24
25
26
 
27
28
29
...
23
24
25
 
26
27
28
29
0
@@ -23,7 +23,7 @@ module Halcyon
0
           Logger.new(STDOUT)
0
         end
0
       end
0
- Halcyon.logger.formatter = proc{|s,t,p,m|"#{s} [#{t.strftime("%Y-%m-%d %H:%M:%S")}] (#{$$}) #{p} :: #{m}\n"}
0
+ Halcyon.logger.formatter = proc{|s,t,p,m|"%5s [%s] (%s) %s :: %s\n" % [s, t.strftime("%Y-%m-%d %H:%M:%S"), $$, p, m]}
0
       Halcyon.logger.progname = Halcyon.root.split('/').last.camel_case
0
       Halcyon.logger.level = Logger.const_get(Halcyon.config[:log_level].upcase)
0
       

Comments

    No one has commented yet.