Module: Rack::Adapter

Module Rack::Adapter

(in files lib/rack/adapter/loader.rb lib/rack/adapter/rails.rb lib/thin.rb )

Adapter to run a Rails app with any supported Rack handler. By default it will try to load the Rails application in the current directory in the development environment.

Options:

 root: Root directory of the Rails app
 environment: Rails environment to run in (development [default], production or test)
 prefix: Set the relative URL root.

Based on fuzed.rubyforge.org/ Rails adapter

Methods

Public Class for(name, options={})

Loads an adapter identified by name using options hash.

    # File lib/rack/adapter/loader.rb, line 33
33:     def self.for(name, options={})
34:       case name.to_sym
35:       when :rails
36:         return Rails.new(options.merge(:root => options[:chdir]))
37:       
38:       when :ramaze
39:         require "#{options[:chdir]}/start"
40:         
41:         Ramaze.trait[:essentials].delete Ramaze::Adapter
42:         Ramaze.start :force => true
43:         
44:         return Ramaze::Adapter::Base
45:         
46:       when :merb
47:         require 'merb-core'
48:         
49:         Merb::Config.setup(:merb_root   => options[:chdir],
50:                            :environment => options[:environment])
51:         Merb.environment = Merb::Config[:environment]
52:         Merb.root = Merb::Config[:merb_root]
53:         Merb::BootLoader.run
54:         
55:         return Merb::Rack::Application.new
56:         
57:       when :halcyon
58:         require 'halcyon'
59:         
60:         $:.unshift(Halcyon.root/'lib')
61:         
62:         return Halcyon::Runner.new
63:         
64:       when :mack
65:         ENV["MACK_ENV"] = options[:environment]
66:         load(::File.join(options[:chdir], "Rakefile"))
67:         require 'mack'
68:         return Mack::Utils::Server.build_app
69:         
70:       when :file
71:         return Rack::File.new(options[:chdir])
72:         
73:       else
74:         raise AdapterNotFound, "Adapter not found: #{name}"
75:         
76:       end
77:     end

Public Class guess(dir)

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 dir/.

    # File lib/rack/adapter/loader.rb, line 25
25:     def self.guess(dir)
26:       ADAPTERS.each do |adapter, file|
27:         return adapter if file && ::File.exist?(::File.join(dir, file))
28:       end
29:       raise AdapterNotFound, "No adapter found for #{dir}"
30:     end