<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,6 @@
 == 0.8.0 Dodgy Dentist release
+ * Make Server.new arguments more flexible, can now specify any of host, port, app or hash options.
+ * Add --backend option to specified which backend to use, closes #55
  * Serve static file only on GET and HEAD requests in Rails adapter, fixes #58
  * Add threaded option to run server in threaded mode, calling the application in a
    thread allowing for concurrency in the Rack adapter, closes #46</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -6,10 +6,10 @@ module Thin
       
       attr_accessor :host, :port
       
-      def initialize(host, port, key=nil)
+      def initialize(host, port, options={})
         @host = host
         @port = port.to_i
-        @key  = key || ''
+        @key  = options[:swiftiply].to_s
         super()
       end
 </diff>
      <filename>lib/thin/backends/swiftiply_client.rb</filename>
    </modified>
    <modified>
      <diff>@@ -37,10 +37,10 @@ module Thin
       def start
         # Select proper backend
         server = case
+        when @options.has_key?(:backend)
+          Server.new(@options[:address], @options[:port], :backend =&gt; eval(@options[:backend], TOPLEVEL_BINDING))
         when @options.has_key?(:socket)
           Server.new(@options[:socket])
-        when @options.has_key?(:swiftiply)
-          Server.new(Backends::SwiftiplyClient.new(@options[:address], @options[:port], @options[:swiftiply]))
         else
           Server.new(@options[:address], @options[:port])
         end</diff>
      <filename>lib/thin/controllers/controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -64,6 +64,7 @@ module Thin
         opts.on(&quot;-y&quot;, &quot;--swiftiply [KEY]&quot;, &quot;Run using swiftiply&quot;)                       { |key| @options[:swiftiply] = key }
         opts.on(&quot;-A&quot;, &quot;--adapter NAME&quot;, &quot;Rack adapter to use &quot; +                       
                                         &quot;(default: auto-detected)&quot;)                     { |name| @options[:adapter] = name }
+        opts.on(&quot;-b&quot;, &quot;--backend CLASS&quot;, &quot;Backend to use, full classname&quot;)              { |name| @options[:backend] = name }
         opts.on(&quot;-c&quot;, &quot;--chdir DIR&quot;, &quot;Change to dir before starting&quot;)                   { |dir| @options[:chdir] = File.expand_path(dir) }
         opts.on(&quot;-r&quot;, &quot;--rackup FILE&quot;, &quot;Load a Rack config file instead of &quot; +
                                        &quot;Rails adapter&quot;)                                 { |file| @options[:rackup] = file }</diff>
      <filename>lib/thin/runner.rb</filename>
    </modified>
    <modified>
      <diff>@@ -52,6 +52,7 @@ module Thin
     
     # Default values
     DEFAULT_TIMEOUT                        = 30 #sec
+    DEFAULT_HOST                           = '0.0.0.0'
     DEFAULT_PORT                           = 3000
     DEFAULT_MAXIMUM_CONNECTIONS            = 1024
     DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS = 512
@@ -84,20 +85,24 @@ module Thin
     # UNIX domain socket on which the server is listening for connections.
     def_delegator :backend, :socket
     
-    def initialize(host_or_socket_or_backend, port=DEFAULT_PORT, app=nil, &amp;block)
-      # Try to intelligently select which backend to use.
-      @backend = case
-      when host_or_socket_or_backend.is_a?(Backends::Base)
-        host_or_socket_or_backend
-      when host_or_socket_or_backend.include?('/')
-        Backends::UnixServer.new(host_or_socket_or_backend)
-      else
-        Backends::TcpServer.new(host_or_socket_or_backend, port.to_i)
+    def initialize(*args, &amp;block)
+      host, port, options = DEFAULT_HOST, DEFAULT_PORT, {}
+      
+      args.each do |arg|
+        case arg
+        when String then host    = arg
+        when Fixnum then port    = arg
+        when Hash   then options = arg
+        else
+          @app = arg if arg.respond_to?(:call)
+        end
       end
       
+      # Try to intelligently select which backend to use.
+      @backend = select_backend(host, port, options)
+      
       load_cgi_multipart_eof_fix
 
-      @app            = app
       @backend.server = self
       
       # Set defaults
@@ -200,6 +205,20 @@ module Thin
         trap('TERM') { stop! }
       end
       
+      def select_backend(host, port, options)
+        case
+        when options.has_key?(:backend)
+          raise ArgumentError, &quot;:backend must be a class&quot; unless options[:backend].is_a?(Class)
+          options[:backend].new(host, port, options)
+        when options.has_key?(:swiftiply)
+          Backends::SwiftiplyClient.new(host, port, options)
+        when host.include?('/')
+          Backends::UnixServer.new(host)
+        else
+          Backends::TcpServer.new(host, port)
+        end
+      end
+      
       # Taken from Mongrel cgi_multipart_eof_fix
       # Ruby 1.8.5 has a security bug in cgi.rb, we need to patch it.
       def load_cgi_multipart_eof_fix</diff>
      <filename>lib/thin/server.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,9 +2,10 @@ require File.dirname(__FILE__) + '/../spec_helper'
 
 describe Server, 'app builder' do
   it &quot;should build app from constructor&quot; do
-    server = Server.new('0.0.0.0', 3000, :works)
+    app = proc {}
+    server = Server.new('0.0.0.0', 3000, app)
     
-    server.app.should == :works
+    server.app.should == app
   end
   
   it &quot;should build app from builder block&quot; do</diff>
      <filename>spec/server/builder_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,7 +10,7 @@ else
       end
       wait_for_socket('0.0.0.0', 3333)
       sleep 2 # HACK ooh boy, I wish I knew how to make those specs more stable...
-      start_server(Backends::SwiftiplyClient.new('0.0.0.0', 5555, nil), nil, :wait_for_socket =&gt; false) do |env|
+      start_server('0.0.0.0', 5555, :backend =&gt; Backends::SwiftiplyClient, :wait_for_socket =&gt; false) do |env|
         body = env.inspect + env['rack.input'].read
         [200, { 'Content-Type' =&gt; 'text/html', 'Content-Length' =&gt; body.size.to_s }, body]
       end</diff>
      <filename>spec/server/swiftiply_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -25,4 +25,59 @@ describe Server do
     @server.threaded = true
     @server.backend.should be_threaded
   end
+end
+
+describe Server, &quot;initialization&quot; do
+  it &quot;should set host and port&quot; do
+    server = Server.new('192.168.1.1', 8080)
+
+    server.host.should == '192.168.1.1'
+    server.port.should == 8080
+  end
+
+  it &quot;should set socket&quot; do
+    server = Server.new('/tmp/thin.sock')
+
+    server.socket.should == '/tmp/thin.sock'
+  end
+  
+  it &quot;should set host, port and app&quot; do
+    app = proc {}
+    server = Server.new('192.168.1.1', 8080, app)
+    
+    server.host.should_not be_nil
+    server.app.should == app
+  end
+
+  it &quot;should set socket and app&quot; do
+    app = proc {}
+    server = Server.new('/tmp/thin.sock', app)
+    
+    server.socket.should_not be_nil
+    server.app.should == app
+  end
+
+  it &quot;should set socket, nil and app&quot; do
+    app = proc {}
+    server = Server.new('/tmp/thin.sock', nil, app)
+    
+    server.socket.should_not be_nil
+    server.app.should == app
+  end
+  
+  it &quot;should set host, port and backend&quot; do
+    server = Server.new('192.168.1.1', 8080, :backend =&gt; Thin::Backends::SwiftiplyClient)
+    
+    server.host.should_not be_nil
+    server.backend.should be_kind_of(Thin::Backends::SwiftiplyClient)
+  end  
+
+  it &quot;should set host, port, app and backend&quot; do
+    app = proc {}
+    server = Server.new('192.168.1.1', 8080, app, :backend =&gt; Thin::Backends::SwiftiplyClient)
+    
+    server.host.should_not be_nil
+    server.app.should == app
+    server.backend.should be_kind_of(Thin::Backends::SwiftiplyClient)
+  end  
 end
\ No newline at end of file</diff>
      <filename>spec/server_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -143,7 +143,7 @@ module Helpers
   end
   
   def start_server(address=DEFAULT_TEST_ADDRESS, port=DEFAULT_TEST_PORT, options={}, &amp;app)
-    @server = Thin::Server.new(address, port, app)
+    @server = Thin::Server.new(address, port, options, app)
     @server.threaded = options[:threaded]
     @server.timeout = 3
     </diff>
      <filename>spec/spec_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>97d1b9edf01c8f6418ed0b82be168b6efd92b940</id>
    </parent>
  </parents>
  <author>
    <name>macournoyer</name>
    <email>macournoyer@gmail.com</email>
  </author>
  <url>http://github.com/macournoyer/thin/commit/01dece1c2b32d9b12d1d2ee64aa78917f2ddaae1</url>
  <id>01dece1c2b32d9b12d1d2ee64aa78917f2ddaae1</id>
  <committed-date>2008-04-03T20:45:53-07:00</committed-date>
  <authored-date>2008-04-03T20:45:53-07:00</authored-date>
  <message>* Make Server.new arguments more flexible, can now specify any of host, port, app or hash options.
* Add --backend option to specified which backend to use, closes #55</message>
  <tree>da0a6446dbb2d7819fa9e2b8e4101fda7de374ec</tree>
  <committer>
    <name>macournoyer</name>
    <email>macournoyer@gmail.com</email>
  </committer>
</commit>
