public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Click here to lend your support to: thin and make a donation at www.pledgie.com !
thin / lib / rack / adapter / loader.rb
100644 46 lines (38 sloc) 1.336 kb
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
43
44
45
46
module Rack
  class AdapterNotFound < RuntimeError; end
  
  module Adapter
    # Guess which adapter to use based on the directory structure
    # or file content.
    # Returns a symbol representing the name of the adapter to use
    # to load the application under <tt>dir/</tt>.
    def self.guess(dir)
      case
      when ::File.exist?("#{dir}/config/environment.rb") then :rails
      when ::File.exist?("#{dir}/start.rb") then :ramaze
      when ::File.exist?("#{dir}/config/init.rb") then :merb
      else
        raise AdapterNotFound, "No adapter found for #{dir}"
      end
    end
    
    # Loads an adapter identified by +name+ using +options+ hash.
    def self.for(name, options={})
      case name.to_sym
      when :rails
        Rails.new(options.merge(:root => options[:chdir]))
      
      when :ramaze
        require "#{options[:chdir]}/start"
 
        Ramaze.trait[:essentials].delete Ramaze::Adapter
        Ramaze.start :force => true
 
        Ramaze::Adapter::Base
 
      # FIXME not working, halp! halp!
      # when :merb
      # require 'merb'
      # require "#{options[:chdir]}/config/init.rb"
      # Merb::BootLoader.run
      # Merb::Rack::Application.new
      
      else
        raise AdapterNotFound, "Adapter not found: #{name}"
        
      end
    end
  end
end