Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote branch 'origin/master'

Conflicts:
	railties/lib/rails/application.rb
  • Loading branch information...
commit 84f1137ef87ff3c8e7cff5e8363d1f116b23fcae 2 parents c4d6d50 + 7a6f73e
Carlhuda authored
View
6 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -35,13 +35,15 @@ def initialize(set)
end
def root(options = {})
+ raise "Can't rename root to #{options[:as].inspect}: root is always named 'root'" if options.include?(:as)
match '/', options.merge(:as => :root)
end
def match(*args)
if args.one? && args.first.is_a?(Hash)
- path = args.first.keys.first
- options = { :to => args.first.values.first }
+ options = args.first
+ path = options.keys.first
+ options[:to] = options.delete(path)
else
path = args.first
options = args.extract_options!
View
2  actionpack/lib/action_dispatch/routing/route_set.rb
@@ -273,7 +273,7 @@ def controller_namespaces
# TODO: Move this into Railties
if defined?(Rails.application)
# Find namespaces in controllers/ directory
- Rails.application.configuration.controller_paths.each do |load_path|
+ Rails.application.config.controller_paths.each do |load_path|
load_path = File.expand_path(load_path)
Dir["#{load_path}/**/*_controller.rb"].collect do |path|
namespaces << File.dirname(path).sub(/#{load_path}\/?/, '')
View
6 actionpack/test/dispatch/routing_test.rb
@@ -22,7 +22,7 @@ def self.matches?(request)
delete 'logout', :to => :destroy, :as => :logout
end
- match 'account/logout' => redirect("/logout")
+ match 'account/logout' => redirect("/logout"), :as => :logout_redirect
match 'account/login', :to => redirect("/login")
match 'account/modulo/:name', :to => redirect("/%{name}s")
@@ -109,7 +109,7 @@ def self.matches?(request)
scope ':access_token', :constraints => { :access_token => /\w{5,5}/ } do
resources :rooms
end
-
+
root :to => 'projects#index'
end
end
@@ -153,6 +153,7 @@ def test_login_redirect
def test_logout_redirect_without_to
with_test_routes do
+ assert_equal '/account/logout', logout_redirect_path
get '/account/logout'
assert_equal 301, @response.status
assert_equal 'http://www.example.com/logout', @response.headers['Location']
@@ -462,6 +463,7 @@ def test_access_token_rooms
def test_root
with_test_routes do
+ assert_equal '/', root_path
get '/'
assert_equal 'projects#index', @response.body
end
View
96 railties/lib/rails/application.rb
@@ -1,89 +1,47 @@
require "fileutils"
+require 'active_support/core_ext/module/delegation'
module Rails
class Application
include Initializable
class << self
- # Stub out App initialize
- def initialize!
- new
- end
+ attr_writer :config
+ alias configure class_eval
+ delegate :initialize!, :load_tasks, :to => :instance
- def new
- @instance ||= begin
- begin
- require config.environment_path
- rescue LoadError
- end
- super
- end
+ private :new
+ def instance
+ @instance ||= new
end
def config
@config ||= Configuration.new(Plugin::Configuration.default)
end
- # TODO: change the plugin loader to use config
- alias configuration config
-
- def config=(config)
- @config = config
- end
-
- def root
- config.root
- end
-
- def load_tasks
- require "rails/tasks"
- Dir["#{root}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext }
- Dir["#{root}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
- task :environment do
- $rails_rake_task = true
- initialize!
- end
- end
-
def routes
ActionController::Routing::Routes
end
-
- def call(env)
- new.call(env)
- end
end
+ delegate :config, :routes, :to => :'self.class'
+ delegate :root, :middleware, :to => :config
attr_reader :route_configuration_files
def initialize
+ require_environment
Rails.application ||= self
-
@route_configuration_files = []
-
- run_initializers(self)
- end
-
- def config
- self.class.config
- end
-
- class << self
- alias configure class_eval
end
- def root
- config.root
- end
-
- alias configuration config
-
- def middleware
- config.middleware
+ def initialize!
+ run_initializers(self)
+ self
end
- def routes
- ActionController::Routing::Routes
+ def require_environment
+ require config.environment_path
+ rescue LoadError
end
def routes_changed_at
@@ -112,6 +70,16 @@ def reload_routes!
routes.disable_clear_and_finalize = false
end
+ def load_tasks
+ require "rails/tasks"
+ Dir["#{root}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext }
+ Dir["#{root}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
+ task :environment do
+ $rails_rake_task = true
+ initialize!
+ end
+ end
+
def initializers
initializers = super
plugins.each { |p| initializers += p.initializers }
@@ -165,7 +133,7 @@ def call(env)
# Create tmp directories
initializer :ensure_tmp_directories_exist do
%w(cache pids sessions sockets).each do |dir_to_make|
- FileUtils.mkdir_p(File.join(config.root, 'tmp', dir_to_make))
+ FileUtils.mkdir_p(File.join(root, 'tmp', dir_to_make))
end
end
@@ -267,14 +235,14 @@ def call(env)
# # already called abort() unless $gems_rake_task is set
# return unless gems_dependencies_loaded
initializer :load_application_initializers do
- Dir["#{configuration.root}/config/initializers/**/*.rb"].sort.each do |initializer|
+ Dir["#{root}/config/initializers/**/*.rb"].sort.each do |initializer|
load(initializer)
end
end
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
initializer :after_initialize do
- configuration.after_initialize_blocks.each do |block|
+ config.after_initialize_blocks.each do |block|
block.call
end
end
@@ -283,8 +251,8 @@ def call(env)
initializer :load_application_classes do
next if $rails_rake_task
- if configuration.cache_classes
- configuration.eager_load_paths.each do |load_path|
+ if config.cache_classes
+ config.eager_load_paths.each do |load_path|
matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
require_dependency file.sub(matcher, '\1')
@@ -295,7 +263,7 @@ def call(env)
# Disable dependency loading during request cycle
initializer :disable_dependency_loading do
- if configuration.cache_classes && !configuration.dependency_loading
+ if config.cache_classes && !config.dependency_loading
ActiveSupport::Dependencies.unhook!
end
end
View
10 railties/lib/rails/commands/server.rb
@@ -41,9 +41,9 @@ def self.start(app)
new(app).start
end
- def initialize(app_const)
+ def initialize(app)
super() # Call Rack::Server#initialize without passing any options to use.
- @app_const = app_const
+ @app = app
end
def start
@@ -69,7 +69,7 @@ def middleware
end
def log_path
- "#{File.expand_path(@app_const.root)}/log/#{options[:environment]}.log"
+ "#{File.expand_path(@app.root)}/log/#{options[:environment]}.log"
end
def default_options
@@ -77,10 +77,10 @@ def default_options
:Port => 3000,
:Host => "0.0.0.0",
:environment => (ENV['RAILS_ENV'] || "development").dup,
- :rack_file => "#{@app_const.root}/config.ru",
+ :rack_file => "#{@app.root}/config.ru",
:daemonize => false,
:debugger => false,
- :pid => "#{@app_const.root}/tmp/pids/server.pid",
+ :pid => "#{@app.root}/tmp/pids/server.pid",
:AccessLog => []
}
end
View
2  railties/lib/rails/generators/rails/app/templates/config.ru
@@ -2,4 +2,4 @@
require ::File.expand_path('../config/environment', __FILE__)
# Dispatch the request
-run <%= app_const%>
+run <%= app_const %>.instance
View
2  railties/lib/rails/generators/rails/app/templates/script/console.tt
@@ -1,3 +1,3 @@
require File.expand_path('../../config/application', __FILE__)
require 'rails/commands/console'
-Rails::Console.start(<%= app_const %>)
+Rails::Console.start(<%= app_const %>.instance)
View
2  railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt
@@ -1,3 +1,3 @@
require File.expand_path('../../config/application', __FILE__)
require 'rails/commands/dbconsole'
-Rails::DBConsole.start(<%= app_const %>)
+Rails::DBConsole.start(<%= app_const %>.instance)
View
2  railties/lib/rails/generators/rails/app/templates/script/server.tt
@@ -1,3 +1,3 @@
require File.expand_path('../../config/application', __FILE__)
require 'rails/commands/server'
-Rails::Server.start(<%= app_const %>)
+Rails::Server.start(<%= app_const %>.instance)
View
2  railties/test/application/configuration_test.rb
@@ -69,7 +69,7 @@ def setup
RUBY
require "#{app_path}/config/application"
- assert AppTemplate::Application.configuration.action_controller.allow_concurrency
+ assert AppTemplate::Application.config.action_controller.allow_concurrency
end
test "the application can be marked as threadsafe when there are no frameworks" do
Please sign in to comment.
Something went wrong with that request. Please try again.