diff options
-rw-r--r-- | actionpack/lib/action_dispatch.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/utils.rb | 20 | ||||
-rw-r--r-- | railties/lib/rails/application.rb | 16 | ||||
-rw-r--r-- | railties/lib/rails/commands/server.rb | 14 | ||||
-rw-r--r-- | railties/test/application/load_test.rb | 12 |
5 files changed, 31 insertions, 32 deletions
diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb index be69a2062b..ff365dac68 100644 --- a/actionpack/lib/action_dispatch.rb +++ b/actionpack/lib/action_dispatch.rb @@ -31,6 +31,7 @@ module ActionDispatch autoload :Request, 'action_dispatch/http/request' autoload :Response, 'action_dispatch/http/response' autoload :StatusCodes, 'action_dispatch/http/status_codes' + autoload :Utils, 'action_dispatch/http/utils' autoload :Callbacks, 'action_dispatch/middleware/callbacks' autoload :ParamsParser, 'action_dispatch/middleware/params_parser' diff --git a/actionpack/lib/action_dispatch/http/utils.rb b/actionpack/lib/action_dispatch/http/utils.rb new file mode 100644 index 0000000000..e04a39935e --- /dev/null +++ b/actionpack/lib/action_dispatch/http/utils.rb @@ -0,0 +1,20 @@ +module ActionDispatch + module Utils + # TODO: Pull this into rack core + # http://github.com/halorgium/rack/commit/feaf071c1de743fbd10bc316830180a9af607278 + def parse_config(config) + if config =~ /\.ru$/ + cfgfile = ::File.read(config) + if cfgfile[/^#\\(.*)/] + opts.parse! $1.split(/\s+/) + end + inner_app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", + nil, config + else + require config + inner_app = Object.const_get(::File.basename(config, '.rb').capitalize) + end + end + module_function :parse_config + end +end diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 7b50d2622e..d762689794 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -2,22 +2,6 @@ require 'action_controller' module Rails class Application - def self.load(path, options = {}) - config = options[:config] || 'config.ru' - config = File.join(path, config) - - if config =~ /\.ru$/ - cfgfile = File.read(config) - if cfgfile[/^#\\(.*)/] - opts.parse!($1.split(/\s+/)) - end - inner_app = eval("::Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config) - else - require config - inner_app = Object.const_get(File.basename(config, '.rb').capitalize) - end - end - def initialize @app = ActionController::Dispatcher.new end diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 743e5a0b07..25f5a8ada5 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -58,23 +58,11 @@ end ENV["RAILS_ENV"] = options[:environment] RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV) -config = options[:config] -if config =~ /\.ru$/ - cfgfile = File.read(config) - if cfgfile[/^#\\(.*)/] - opts.parse!($1.split(/\s+/)) - end - inner_app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config) -else - require config - inner_app = Object.const_get(File.basename(config, '.rb').capitalize) -end - app = Rack::Builder.new { use Rails::Rack::LogTailer unless options[:detach] use Rails::Rack::Debugger if options[:debugger] use Rails::Rack::Static - run inner_app + run ActionDispatch::Utils.parse_config(options[:config]) }.to_app puts "=> Call with -d to detach" diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb index 6dda47bb8f..c5bc80197d 100644 --- a/railties/test/application/load_test.rb +++ b/railties/test/application/load_test.rb @@ -15,7 +15,13 @@ module ApplicationTests end test "running Rails::Application.load on the path returns a (vaguely) useful application" do - @app = Rails::Application.load app_path + app_file "config.ru", <<-CONFIG + require File.dirname(__FILE__) + '/config/environment' + use Rails::Rack::Static + run ActionController::Dispatcher.new + CONFIG + + @app = ActionDispatch::Utils.parse_config("#{app_path}/config.ru") assert_welcome get("/") end @@ -37,7 +43,7 @@ module ApplicationTests run proc {|env| [200, {"Content-Type" => "text/html"}, ["VICTORY"]] } CONFIG - @app = Rails::Application.load app_path, :config => "config.ru" + @app = ActionDispatch::Utils.parse_config("#{app_path}/config.ru") assert_body "VICTORY", get("/omg") assert_header "Config-Ru-Test", "TESTING", get("/omg") @@ -48,7 +54,7 @@ module ApplicationTests Myapp = proc {|env| [200, {"Content-Type" => "text/html"}, ["OMG ROBOTS"]] } CONFIG - @app = Rails::Application.load app_path, :config => "myapp.rb" + @app = ActionDispatch::Utils.parse_config("#{app_path}/myapp.rb") assert_body "OMG ROBOTS", get("/omg") end |