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:
update new rack middleware machinery to be more merb style in the 
bootloader

allow for new rack.rb, update specs to all pass with new middleware
ezmobius (author)
Tue May 13 18:24:00 -0700 2008
commit  5259c13979a8cd3c7e232dc01dde91bafc9af9a1
tree    9d8ad434ddb4b8471da6a59f0e70e144049c0c99
parent  78ae5652ecce8f6f6bf09e5608f3aa394ab638be
...
563
564
565
 
566
567
568
...
571
572
573
574
 
 
 
 
 
 
 
575
576
577
...
563
564
565
566
567
568
569
...
572
573
574
 
575
576
577
578
579
580
581
582
583
584
0
@@ -563,6 +563,7 @@
0
   # the context of a Rack::Builder.new { } block. Allows for mounting
0
   # additional apps or middleware.
0
   def self.run
0
+ require 'rack'
0
     if File.exists?(Merb.dir_for(:config) / "rack.rb")
0
       Merb::Config[:rackup] ||= Merb.dir_for(:config) / "rack.rb"
0
     end
0
@@ -571,7 +572,13 @@
0
       rackup_code = File.read(Merb::Config[:rackup])
0
       Merb::Config[:app] = eval("::Rack::Builder.new {( #{rackup_code}\n )}.to_app", TOPLEVEL_BINDING, Merb::Config[:rackup])
0
     else
0
- Merb::Config[:app] = ::Merb::Rack::Application.new
0
+ Merb::Config[:app] = ::Rack::Builder.new {
0
+ if prefix = ::Merb::Config[:path_prefix]
0
+ use Merb::Rack::PathPrefix, prefix
0
+ end
0
+ use Merb::Rack::Static, Merb.dir_for(:public)
0
+ run Merb::Rack::Application.new
0
+ }.to_app
0
     end
0
   end
0
 end
...
7
8
9
 
10
11
12
13
14
15
16
17
18
 
 
19
20
...
7
8
9
10
11
12
13
14
 
 
 
 
 
15
16
17
18
0
@@ -7,15 +7,13 @@
0
     autoload :EventedMongrel, "merb-core/rack/adapter/evented_mongrel"
0
     autoload :FastCGI, "merb-core/rack/adapter/fcgi"
0
     autoload :Irb, "merb-core/rack/adapter/irb"
0
+ autoload :Middleware, "merb-core/rack/middleware"
0
     autoload :Mongrel, "merb-core/rack/adapter/mongrel"
0
     autoload :Runner, "merb-core/rack/adapter/runner"
0
     autoload :Thin, "merb-core/rack/adapter/thin"
0
     autoload :WEBrick, "merb-core/rack/adapter/webrick"
0
-
0
- autoload :Deferral, "merb-core/rack/apps/deferral"
0
- autoload :MerbApplication, "merb-core/rack/apps/merb_application"
0
- autoload :PathPrefix, "merb-core/rack/apps/path_prefix"
0
- autoload :Static, "merb-core/rack/apps/static"
0
+ autoload :PathPrefix, "merb-core/rack/apps/path_prefix"
0
+ autoload :Static, "merb-core/rack/apps/static"
0
   end # Rack
0
 end # Merb
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
 
 
 
 
 
 
 
 
 
 
 
 
40
41
42
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
0
@@ -1,42 +1,18 @@
0
-module Merb
0
- module Rack
0
- class AbstractMiddleware
0
-
0
- def initialize(app)
0
- @app = app
0
- end
0
-
0
- def deferred?(env)
0
- @app.deferred?(env)
0
- end
0
-
0
- def call(env)
0
- @app.call(env)
0
- end
0
-
0
- end
0
- end
0
-end
0
-
0
-
0
-module Merb
0
-
0
+module Merb
0
   module Rack
0
-
0
- class Application < Merb::Rack::AbstractMiddleware
0
- # ==== Parameters
0
- # options<Hash>::
0
- # Options for creating a new application. Currently ignored.
0
- def initialize(options={})
0
- @app = ::Rack::Builder.new {
0
- if prefix = ::Merb::Config[:path_prefix]
0
- use Merb::Rack::PathPrefix, prefix
0
- end
0
- use Merb::Rack::Deferral
0
- use Merb::Rack::Static, Merb.dir_for(:public)
0
- run Merb::Rack::MerbApplication.new
0
- }.to_app
0
- end
0
+ class Application
0
+
0
+ def call(env)
0
+ begin
0
+ controller = ::Merb::Dispatcher.handle(env)
0
+ rescue Object => e
0
+ return [500, {"Content-Type"=>"text/html"}, e.message + "<br/>" + e.backtrace.join("<br/>")]
0
+ end
0
+ Merb.logger.info "\n\n"
0
+ Merb.logger.flush
0
+ [controller.status, controller.headers, controller.body]
0
+ end
0
+
0
     end
0
   end
0
 end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,18 +1 @@
0
-module Merb
0
- module Rack
0
- class Deferral < Merb::Rack::AbstractMiddleware
0
-
0
- def deferred?(env)
0
- path = env['PATH_INFO'] ? env['PATH_INFO'].chomp('/') : ""
0
- if path =~ Merb.deferred_actions
0
- Merb.logger.info! "Deferring Request: #{path}"
0
- true
0
- else
0
- false
0
- end
0
- end
0
-
0
- end
0
- end
0
-end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,19 +1 @@
0
-module Merb
0
- module Rack
0
- class MerbApplication
0
-
0
- def call(env)
0
- begin
0
- controller = ::Merb::Dispatcher.handle(env)
0
- rescue Object => e
0
- return [500, {"Content-Type"=>"text/html"}, e.message + "<br/>" + e.backtrace.join("<br/>")]
0
- end
0
- Merb.logger.info "\n\n"
0
- Merb.logger.flush
0
- [controller.status, controller.headers, controller.body]
0
- end
0
-
0
- end
0
- end
0
-end
...
1
2
3
 
4
5
6
...
1
2
 
3
4
5
6
0
@@ -1,6 +1,6 @@
0
 module Merb
0
   module Rack
0
- class PathPrefix < Merb::Rack::AbstractMiddleware
0
+ class PathPrefix < Merb::Rack::Middleware
0
 
0
       def initialize(app, path_prefix = nil)
0
         super(app)
...
1
2
3
 
4
5
6
7
 
8
9
10
...
1
2
 
3
4
5
6
 
7
8
9
10
0
@@ -1,10 +1,10 @@
0
 module Merb
0
   module Rack
0
- class Static < Merb::Rack::AbstractMiddleware
0
+ class Static < Merb::Rack::Middleware
0
 
0
       def initialize(app,directory)
0
         super(app)
0
- @static_server = ::Rack::File.new directory
0
+ @static_server = ::Rack::File.new(directory)
0
       end
0
       
0
       def call(env)
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
0
@@ -1 +1,26 @@
0
+module Merb
0
+ module Rack
0
+ class Middleware
0
+
0
+ def initialize(app)
0
+ @app = app
0
+ end
0
+
0
+ def deferred?(env)
0
+ path = env['PATH_INFO'] ? env['PATH_INFO'].chomp('/') : ""
0
+ if path =~ Merb.deferred_actions
0
+ Merb.logger.info! "Deferring Request: #{path}"
0
+ true
0
+ else
0
+ false
0
+ end
0
+ end
0
+
0
+ def call(env)
0
+ @app.call(env)
0
+ end
0
+
0
+ end
0
+ end
0
+end
...
6
7
8
9
 
10
11
12
...
6
7
8
 
9
10
11
12
0
@@ -6,7 +6,7 @@
0
     options = {:merb_root => File.dirname(__FILE__) / 'fixture'}
0
     Merb::Config.setup(options)
0
     app = Merb::BootLoader::RackUpApplication.run
0
- app.class.should == Merb::Rack::Application
0
+ app.class.should == Merb::Rack::Static
0
   end
0
 
0
   it "should use rackup config that we specified" do
...
 
 
 
 
 
 
 
 
 
 
1
...
1
2
3
4
5
6
7
8
9
10
11
0
@@ -1,2 +1,12 @@
0
+# use PathPrefix Middleware if :path_prefix is set in Merb::Config
0
+if prefix = ::Merb::Config[:path_prefix]
0
+ use Merb::Rack::PathPrefix, prefix
0
+end
0
+
0
+# comment this out if you are running merb behind a load balancer
0
+# that serves static files
0
+use Merb::Rack::Static, Merb.dir_for(:public)
0
+
0
+# this is our main merb application
0
 run Merb::Rack::Application.new
...
20
21
22
23
 
 
 
 
 
 
 
24
25
26
...
20
21
22
 
23
24
25
26
27
28
29
30
31
32
0
@@ -20,7 +20,13 @@
0
 
0
   before do
0
     Merb::Config[:path_prefix] = "/quux"
0
- @app = Merb::Rack::Application.new
0
+ @app = ::Rack::Builder.new {
0
+ if prefix = ::Merb::Config[:path_prefix]
0
+ use Merb::Rack::PathPrefix, prefix
0
+ end
0
+ use Merb::Rack::Static, Merb.dir_for(:public)
0
+ run Merb::Rack::Application.new
0
+ }.to_app
0
     @nullobj = mock('controller', :null_object => true)
0
   end
0
   

Comments

    No one has commented yet.