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:
Modify dispatcher to be sane to XHRs; add to_json to dictionaries.
wycats (author)
Wed Mar 19 18:48:51 -0700 2008
commit  47c48645b52b66de1360e3cce5e87035cd36b270
tree    c0e167933889cbf59b2600bc69f8d90a4af07f5e
parent  bd6814e14a9da3c161e1f6b14b71f88b5a9f0748
...
72
73
74
75
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
78
79
...
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
0
@@ -72,8 +72,28 @@ class Merb::Dispatcher
0
     # to the error controller
0
     rescue => exception
0
       Merb.logger.error(Merb.exception(exception))
0
- exception = controller_exception(exception)
0
- dispatch_exception(request, exception)
0
+ unless request.xhr?
0
+ exception = controller_exception(exception)
0
+ dispatch_exception(request, exception)
0
+ else
0
+ Struct.new(:headers, :status, :body).new({}, 500,
0
+ <<-HERE
0
+#{exception.message}
0
+
0
+Params:
0
+#{(request.params || {}).map { |p,v| " #{p}: #{v}\n"}.join("\n")}
0
+
0
+Session:
0
+#{(request.session || {}).map { |p,v| " #{p}: #{v}\n"}.join("\n")}
0
+
0
+Cookies:
0
+#{(request.cookies || {}).map { |p,v| " #{p}: #{v}\n"}.join("\n")}
0
+
0
+Stacktrace:
0
+#{exception.backtrace.join("\n")}
0
+ HERE
0
+ )
0
+ end
0
     end
0
     
0
     private
...
407
408
409
 
 
 
 
 
 
 
 
 
 
 
410
411
412
...
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
0
@@ -407,6 +407,17 @@ class Dictionary
0
     each { |k,v| ary << [k,v] }
0
     ary
0
   end
0
+
0
+ def to_json
0
+ buf = "{"
0
+ map do |k,v|
0
+ buf << k.to_s.inspect
0
+ buf << ": "
0
+ buf << v.to_json
0
+ end.join(", ")
0
+ buf << "}"
0
+ buf
0
+ end
0
 
0
   def to_s
0
     self.to_a.to_s
...
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
0
@@ -0,0 +1,9 @@
0
+require 'benchmark'
0
+require 'zlib'
0
+
0
+TIMES = (ARGV[0] || 100_000).to_i
0
+
0
+Benchmark.bmbm do |x|
0
+ x.report("instantiate") { TIMES.times { [1,2] }}
0
+ x.report("zlib") { TIMES.times { 1.object_id + 2.object_id }}
0
+end

Comments

    No one has commented yet.