Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract "parse_config" into AD

  • Loading branch information...
commit dfbd3b94094d54483a47faa9d927370df476f572 1 parent accd9b4
@josh josh authored
View
1  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'
View
20 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
View
16 railties/lib/rails/application.rb
@@ -2,22 +2,6 @@
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
View
14 railties/lib/rails/commands/server.rb
@@ -58,23 +58,11 @@
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"
View
12 railties/test/application/load_test.rb
@@ -15,7 +15,13 @@ def setup
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 @@ def call(env)
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 @@ def call(env)
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
Please sign in to comment.
Something went wrong with that request. Please try again.