Module: Rack::Adapter
- Defined in:
- lib/thin.rb,
lib/rack/adapter/rails.rb,
lib/rack/adapter/loader.rb
Defined Under Namespace
Classes: Rails
Class Method Summary collapse
-
.for(name, options = {}) ⇒ Object
Loads an adapter identified by
name
usingoptions
hash. -
.guess(dir) ⇒ Object
Guess which adapter to use based on the directory structure or file content.
-
.load(config) ⇒ Object
Load a Rack application from a Rack config file (.ru).
Class Method Details
.for(name, options = {}) ⇒ Object
Loads an adapter identified by name
using options
hash.
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rack/adapter/loader.rb', line 40 def self.for(name, ={}) ENV['RACK_ENV'] = [:environment] case name.to_sym when :rack return load(::File.join([:chdir], "config.ru")) when :rails return Rails.new(.merge(:root => [:chdir])) when :ramaze require "#{[: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 => [:chdir], :environment => [: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') return Halcyon::Runner.new when :mack ENV["MACK_ENV"] = [:environment] load(::File.join([:chdir], "Rakefile")) require 'mack' return Mack::Utils::Server.build_app when :file return Rack::File.new([:chdir]) else raise AdapterNotFound, "Adapter not found: #{name}" end end |
.guess(dir) ⇒ Object
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/
.
26 27 28 29 30 31 |
# File 'lib/rack/adapter/loader.rb', line 26 def self.guess(dir) ADAPTERS.each do |adapter, file| return adapter if file && ::File.exist?(::File.join(dir, file)) end raise AdapterNotFound, "No adapter found for #{dir}" end |
.load(config) ⇒ Object
Load a Rack application from a Rack config file (.ru).
34 35 36 37 |
# File 'lib/rack/adapter/loader.rb', line 34 def self.load(config) rackup_code = ::File.read(config) eval("Rack::Builder.new {( #{rackup_code}\n )}.to_app", TOPLEVEL_BINDING, config) end |