Take the 2008 Git User's Survey and help out! [ hide ]

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:
macournoyer (author)
Sat Apr 05 11:52:25 -0700 2008
commit  dc472b681619c0134db30e7d68b2edbfb1a02076
tree    9282fe22e4104fb25a5352343ca1817837669c0d
parent  f3c09c3075e413c48e076a52ea0016a0250a53da
thin / lib / rack / adapter / loader.rb
100644 69 lines (54 sloc) 1.996 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module Rack
  class AdapterNotFound < RuntimeError; end
 
  # Hash used to guess which adapter to use in <tt>Adapter.for</tt>.
  # Framework name => file unique to this framework.
  # +nil+ for value to never guess.
  ADAPTERS = {
    :rails => "config/environment.rb",
    :ramaze => "start.rb",
    :merb => "config/init.rb",
    :halcyon => 'runner.ru',
    :file => nil
  }
    
  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)
      ADAPTERS.each_pair do |adapter, file|
        return adapter if file && ::File.exist?(::File.join(dir, file))
      end
      raise AdapterNotFound, "No adapter found for #{dir}"
    end
    
    # Loads an adapter identified by +name+ using +options+ hash.
    def self.for(name, options={})
      case name.to_sym
      when :rails
        return Rails.new(options.merge(:root => options[:chdir]))
      
      when :ramaze
        require "#{options[:chdir]}/start"
 
        Ramaze.trait[:essentials].delete Ramaze::Adapter
        Ramaze.start :force => true
 
        return Ramaze::Adapter::Base
 
      when :merb
        require 'merb-core'
 
        Merb::Config.setup(:merb_root => options[:chdir],
                           :environment => options[:environment])
        Merb.environment = Merb::Config[:environment]
        Merb.root = Merb::Config[:merb_root]
        Merb::BootLoader.run
 
        return Merb::Rack::Application.new
      
      when :halcyon
        require 'halcyon'
        
        $:.unshift(Halcyon.root/'lib')
        Halcyon::Runner.load_config Halcyon.root/'config'/'config.yml'
        
        return Halcyon::Runner.new
      
      when :file
        return Rack::File.new(options[:chdir])
      
      else
        raise AdapterNotFound, "Adapter not found: #{name}"
        
      end
    end
  end
end