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:
Refactor Rack loader.
List supported adapters in command usage.
Add file adapter to built-in adapter, serve static files in current 
directory.
macournoyer (author)
Sat Apr 05 11:52:25 -0700 2008
commit  dc472b681619c0134db30e7d68b2edbfb1a02076
tree    9282fe22e4104fb25a5352343ca1817837669c0d
parent  f3c09c3075e413c48e076a52ea0016a0250a53da
...
1
 
 
2
3
4
...
1
2
3
4
5
6
0
@@ -1,4 +1,6 @@
0
 == 0.8.0 Dodgy Dentist release
0
+ * List supported adapters in command usage.
0
+ * Add file adapter to built-in adapter, serve static files in current directory.
0
  * Allow disabling signal handling in Server with :signals => false
0
  * Make Server.new arguments more flexible, can now specify any of host, port, app or hash options.
0
  * Add --backend option to specified which backend to use, closes #55
...
1
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
8
9
10
11
12
13
14
15
16
 
 
17
 
18
19
20
...
49
50
51
 
 
 
52
53
54
...
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
...
56
57
58
59
60
61
62
63
64
0
@@ -1,20 +1,27 @@
0
 module Rack
0
   class AdapterNotFound < RuntimeError; end
0
-
0
- module Adapter
0
+
0
+ # Hash used to guess which adapter to use in <tt>Adapter.for</tt>.
0
+ # Framework name => file unique to this framework.
0
+ # +nil+ for value to never guess.
0
+ ADAPTERS = {
0
+ :rails => "config/environment.rb",
0
+ :ramaze => "start.rb",
0
+ :merb => "config/init.rb",
0
+ :halcyon => 'runner.ru',
0
+ :file => nil
0
+ }
0
+
0
+ module Adapter
0
     # Guess which adapter to use based on the directory structure
0
     # or file content.
0
     # Returns a symbol representing the name of the adapter to use
0
     # to load the application under <tt>dir/</tt>.
0
     def self.guess(dir)
0
- case
0
- when ::File.exist?("#{dir}/config/environment.rb") then :rails
0
- when ::File.exist?("#{dir}/start.rb") then :ramaze
0
- when ::File.exist?("#{dir}/config/init.rb") then :merb
0
- when ::File.exist?("#{dir}/runner.ru") then :halcyon
0
- else
0
- raise AdapterNotFound, "No adapter found for #{dir}"
0
+ ADAPTERS.each_pair do |adapter, file|
0
+ return adapter if file && ::File.exist?(::File.join(dir, file))
0
       end
0
+ raise AdapterNotFound, "No adapter found for #{dir}"
0
     end
0
     
0
     # Loads an adapter identified by +name+ using +options+ hash.
0
@@ -49,6 +56,9 @@
0
         Halcyon::Runner.load_config Halcyon.root/'config'/'config.yml'
0
         
0
         return Halcyon::Runner.new
0
+
0
+ when :file
0
+ return Rack::File.new(options[:chdir])
0
       
0
       else
0
         raise AdapterNotFound, "Adapter not found: #{name}"
...
62
63
64
65
66
67
68
 
 
69
70
 
 
71
72
73
74
75
 
 
76
77
78
...
100
101
102
 
103
104
105
...
62
63
64
 
 
 
 
65
66
67
 
68
69
70
71
72
 
 
73
74
75
76
77
...
99
100
101
102
103
104
105
0
@@ -62,17 +62,16 @@
0
         opts.on("-p", "--port PORT", "use PORT (default: #{@options[:port]})") { |port| @options[:port] = port.to_i }
0
         opts.on("-S", "--socket FILE", "bind to unix domain socket") { |file| @options[:socket] = file }
0
         opts.on("-y", "--swiftiply [KEY]", "Run using swiftiply") { |key| @options[:swiftiply] = key }
0
- opts.on("-A", "--adapter NAME", "Rack adapter to use " +
0
- "(default: auto-detected)") { |name| @options[:adapter] = name }
0
- opts.on("-b", "--backend CLASS", "Backend to use, full classname") { |name| @options[:backend] = name }
0
- opts.on("-c", "--chdir DIR", "Change to dir before starting") { |dir| @options[:chdir] = File.expand_path(dir) }
0
+ opts.on("-A", "--adapter NAME", "Rack adapter to use (default: autodetect)",
0
+ "(#{Rack::ADAPTERS.keys.join(', ')})") { |name| @options[:adapter] = name }
0
         opts.on("-r", "--rackup FILE", "Load a Rack config file instead of " +
0
- "Rails adapter") { |file| @options[:rackup] = file }
0
+ "Rack adapter") { |file| @options[:rackup] = file }
0
+ opts.on("-c", "--chdir DIR", "Change to dir before starting") { |dir| @options[:chdir] = File.expand_path(dir) }
0
         opts.on( "--stats PATH", "Mount the Stats adapter under PATH") { |path| @options[:stats] = path }
0
         
0
         opts.separator ""
0
- opts.separator "Rails options:"
0
- opts.on("-e", "--environment ENV", "Rails environment " +
0
+ opts.separator "Adapter options:"
0
+ opts.on("-e", "--environment ENV", "Framework environment " +
0
                                            "(default: #{@options[:environment]})") { |env| @options[:environment] = env }
0
         opts.on( "--prefix PATH", "Mount the app under PATH (start with /)") { |path| @options[:prefix] = path }
0
         
0
@@ -100,6 +99,7 @@
0
         opts.separator ""
0
         opts.separator "Tuning options:"
0
         
0
+ opts.on("-b", "--backend CLASS", "Backend to use, full classname") { |name| @options[:backend] = name }
0
         opts.on("-t", "--timeout SEC", "Request or command timeout in sec " +
0
                                        "(default: #{@options[:timeout]})") { |sec| @options[:timeout] = sec.to_i }
0
         opts.on( "--max-conns NUM", "Maximum number of connections " +
...
9
10
11
12
 
13
14
15
16
17
18
 
 
 
 
 
19
20
21
...
9
10
11
 
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
0
@@ -9,13 +9,18 @@
0
     Rack::Adapter.guess(@rails_path).should == :rails
0
   end
0
   
0
- it "should raise error when can't guess from dir" do
0
+ it "should return nil when can't guess from dir" do
0
     proc { Rack::Adapter.guess('.') }.should raise_error(Rack::AdapterNotFound)
0
   end
0
   
0
   it "should load Rails adapter" do
0
     Rack::Adapter::Rails.should_receive(:new)
0
     Rack::Adapter.for(:rails, :chdir => @rails_path)
0
+ end
0
+
0
+ it "should load File adapter" do
0
+ Rack::File.should_receive(:new)
0
+ Rack::Adapter.for(:file)
0
   end
0
   
0
   it "should raise error when adapter can't be found" do

Comments

    No one has commented yet.