public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Search Repo:
Allow rackup .rb files by getting a conventionally named constant as the 
app

This is written per spec in the rackup binary
bmizerany (author)
Sun Apr 20 16:00:16 -0700 2008
commit  1ff0e8a049ecdf0781e959f096e2bfd71d5c5032
tree    39d268ba7e479b019fb2187c0076a7e9f84339a6
parent  a9acdec985583b0a9dd539417634b2c0eaee3b40
...
 
...
1
0
@@ -1 +1,2 @@
0
+Myapp = lambda { |env| [200, {}, 'this is my app!'] }
...
161
162
163
164
165
 
 
 
 
 
 
 
 
 
 
166
167
168
...
161
162
163
 
 
164
165
166
167
168
169
170
171
172
173
174
175
176
0
@@ -161,8 +161,16 @@
0
         end
0
         
0
         def load_rackup_config
0
- rackup_code = File.read(@options[:rackup])
0
- eval("Rack::Builder.new {( #{rackup_code}\n )}.to_app", TOPLEVEL_BINDING, @options[:rackup])
0
+ case @options[:rackup]
0
+ when /\.rb$/
0
+ Kernel.load(@options[:rackup])
0
+ Object.const_get(File.basename(@options[:rackup], '.rb').capitalize.to_sym)
0
+ when /\.ru$/
0
+ rackup_code = File.read(@options[:rackup])
0
+ eval("Rack::Builder.new {( #{rackup_code}\n )}.to_app", TOPLEVEL_BINDING, @options[:rackup])
0
+ else
0
+ raise "Invalid rackup file. please specify either a .ru or .rb file"
0
+ end
0
         end
0
     end
0
   end
...
63
64
65
66
 
67
68
69
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
72
73
...
75
76
77
 
78
79
80
...
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
...
89
90
91
92
93
94
95
0
@@ -63,11 +63,25 @@
0
   end
0
   
0
   it "should load app from Rack config" do
0
- @controller.options[:rackup] = 'example/config.ru'
0
+ @controller.options[:rackup] = File.dirname(__FILE__) + '/../../example/config.ru'
0
     @controller.start
0
     
0
     @server.app.class.should == Proc
0
   end
0
+
0
+ it "should load app from ruby file" do
0
+ @controller.options[:rackup] = filename = File.dirname(__FILE__) + '/../../example/myapp.rb'
0
+ @controller.start
0
+
0
+ @server.app.should == Myapp
0
+ end
0
+
0
+ it "should throwup if rackup is not a .ru or .rb file" do
0
+ proc do
0
+ @controller.options[:rackup] = filename = File.dirname(__FILE__) + '/../../example/myapp.foo'
0
+ @controller.start
0
+ end.should raise_error(RuntimeError, /please/)
0
+ end
0
   
0
   it "should set server as threaded" do
0
     @controller.options[:threaded] = true
0
@@ -75,6 +89,7 @@
0
     
0
     @server.threaded.should be_true
0
   end
0
+
0
 end
0
 
0
 describe Controller do

Comments

    No one has commented yet.