diff options
author | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-09-25 17:42:53 -0700 |
---|---|---|
committer | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-09-25 17:42:53 -0700 |
commit | 4129449594ad3d8ff2f8fb4836104f25406a104f (patch) | |
tree | 4c9f1c0de51cee6e37511e0c0e73550a982e78e0 /railties/lib/rails/application.rb | |
parent | 088ce2904d63d15979de561b913e3e88e656f3fa (diff) | |
download | rails-4129449594ad3d8ff2f8fb4836104f25406a104f.tar.gz rails-4129449594ad3d8ff2f8fb4836104f25406a104f.tar.bz2 rails-4129449594ad3d8ff2f8fb4836104f25406a104f.zip |
Start Rails::Application object
Diffstat (limited to 'railties/lib/rails/application.rb')
-rw-r--r-- | railties/lib/rails/application.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb new file mode 100644 index 0000000000..e379504f54 --- /dev/null +++ b/railties/lib/rails/application.rb @@ -0,0 +1,58 @@ +require 'action_controller' + +module Rails + class Application + # Loads a Rails application from a directory and returns a Rails + # Application object that responds to #call(env) + def self.load(path, options = {}) + require "#{path}/config/environment" + new(path, options) + end + + def initialize(path, options) + @path = path + + ensure_tmp_dirs + + if options[:config] + config = File.join(path, options[:config]) + config = nil unless File.exist?(config) + end + + @app = ::Rack::Builder.new { + use Rails::Rack::LogTailer unless options[:detach] + use Rails::Rack::Debugger if options[:debugger] + if options[:path] + base = options[:path] + ActionController::Base.relative_url_root = base + end + + map base || "/" do + use Rails::Rack::Static + + if config && config =~ /\.ru$/ + instance_eval(File.read(config), config) + elsif config + require config + run Object.const_get(File.basename(config, '.rb').capitalize) + else + run ActionController::Dispatcher.new + end + end + }.to_app + end + + def call(env) + @app.call(env) + end + + private + + def ensure_tmp_dirs + %w(cache pids sessions sockets).each do |dir_to_make| + FileUtils.mkdir_p(File.join(@path, 'tmp', dir_to_make)) + end + end + + end +end
\ No newline at end of file |