Permalink
Browse files

Massive cleanup in Railties and load stack.

  • Loading branch information...
1 parent 2df1810 commit 7fcf8590e788cef8b64cc266f75931c418902ca9 @josevalim josevalim committed Jan 21, 2010
@@ -19,12 +19,6 @@ class Railtie < Rails::Railtie
ActionController::Base.logger ||= Rails.logger
end
- # Routing must be initialized after plugins to allow the former to extend the routes
- initializer "action_controller.initialize_routing" do |app|
- app.route_configuration_files << app.config.routes_configuration_file
- app.route_configuration_files << app.config.builtin_routes_configuration_file
- end
-
initializer "action_controller.initialize_framework_caches" do
ActionController::Base.cache_store ||= RAILS_CACHE
end
View
@@ -5,9 +5,10 @@
require 'active_support/core_ext/logger'
require 'rails/initializable'
-require 'rails/application'
require 'rails/railtie'
require 'rails/plugin'
+require 'rails/engine'
+require 'rails/application'
require 'rails/railties_path'
require 'rails/version'
require 'rails/rack'
@@ -1,31 +1,37 @@
require "fileutils"
-require 'active_support/core_ext/module/delegation'
module Rails
- class Application
+ class Application < Engine
include Initializable
class << self
- attr_writer :config
- alias configure class_eval
- delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance
+ alias :configure :class_eval
+ delegate :initialize!, :load_tasks, :load_generators, :to => :instance
private :new
def instance
@instance ||= new
end
def config
- @config ||= Configuration.new(Plugin::Configuration.default)
+ @config ||= Configuration.new(root)
+ end
+
+ def root
+ @root ||= find_root_with_file_flag("config.ru", Dir.pwd)
+ end
+
+ def inherited(base)
+ super
+ Railtie.plugins.delete(base)
end
def routes
ActionController::Routing::Routes
end
end
- delegate :config, :routes, :to => :'self.class'
- delegate :root, :middleware, :to => :config
+ delegate :routes, :to => :'self.class'
attr_reader :route_configuration_files
def initialize
@@ -38,12 +44,7 @@ def initialize!
run_initializers(self)
self
end
-
- def require_environment
- require config.environment_path
- rescue LoadError
- end
-
+
def routes_changed_at
routes_changed_at = nil
@@ -59,6 +60,7 @@ def routes_changed_at
end
def reload_routes!
+ routes = Rails::Application.routes
routes.disable_clear_and_finalize = true
routes.clear!
@@ -70,6 +72,12 @@ def reload_routes!
routes.disable_clear_and_finalize = false
end
+
+ def require_environment
+ require config.environment_path
+ rescue LoadError
+ end
+
def load_tasks
require "rails/tasks"
plugins.each { |p| p.load_tasks }
@@ -114,37 +122,23 @@ def call(env)
app.call(env)
end
- initializer :load_application_initializers do
- Dir["#{root}/config/initializers/**/*.rb"].sort.each do |initializer|
- load(initializer)
- end
+ initializer :build_middleware_stack, :after => :load_application_initializers do
+ app
end
- initializer :build_middleware_stack do
- app
+ initializer :add_builtin_route do |app|
+ if Rails.env.development?
+ app.route_configuration_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb')
+ end
end
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
- initializer :after_initialize do
+ initializer :after_initialize, :after => :build_middleware_stack do
config.after_initialize_blocks.each do |block|
block.call
end
end
- # Eager load application classes
- initializer :load_application_classes do
- next if $rails_rake_task
-
- 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')
- end
- end
- end
- end
-
# Disable dependency loading during request cycle
initializer :disable_dependency_loading do
if config.cache_classes && !config.dependency_loading
@@ -12,30 +12,25 @@ def initialize(application)
require "active_support/all" unless config.active_support.bare
end
- # Set the <tt>$LOAD_PATH</tt> based on the value of
- # Configuration#load_paths. Duplicates are removed.
- initializer :set_load_path do
- config.paths.add_to_load_path
- $LOAD_PATH.uniq!
- end
-
- # Set the paths from which Rails will automatically load source files, and
- # the load_once paths.
- initializer :set_autoload_paths do
- require 'active_support/dependencies'
- ActiveSupport::Dependencies.load_paths = expand_load_path(config.load_paths)
- ActiveSupport::Dependencies.load_once_paths = expand_load_path(config.load_once_paths)
-
- extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths
- unless extra.empty?
- abort <<-end_error
- load_once_paths must be a subset of the load_paths.
- Extra items in load_once_paths: #{extra * ','}
- end_error
+ initializer :initialize_logger do
+ Rails.logger ||= config.logger || begin
+ logger = ActiveSupport::BufferedLogger.new(config.paths.log.to_a.first)
+ logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase)
+ logger.auto_flushing = false if Rails.env.production?
+ logger
+ rescue StandardError => e
+ logger = ActiveSupport::BufferedLogger.new(STDERR)
+ logger.level = ActiveSupport::BufferedLogger::WARN
+ logger.warn(
+ "Rails Error: Unable to access log file. Please ensure that #{config.log_path} exists and is chmod 0666. " +
+ "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
+ )
+ logger
end
+ end
- # Freeze the arrays so future modifications will fail rather than do nothing mysteriously
- config.load_once_paths.freeze
+ initializer :container do
+ # FIXME This is just a dumb initializer used as hook
end
# Create tmp directories
@@ -63,29 +58,6 @@ def initialize(application)
end
end
- initializer :initialize_logger do
- Rails.logger ||= config.logger || begin
- logger = ActiveSupport::BufferedLogger.new(config.log_path)
- logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase)
- logger.auto_flushing = false if Rails.env.production?
- logger
- rescue StandardError => e
- logger = ActiveSupport::BufferedLogger.new(STDERR)
- logger.level = ActiveSupport::BufferedLogger::WARN
- logger.warn(
- "Rails Error: Unable to access log file. Please ensure that #{config.log_path} exists and is chmod 0666. " +
- "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
- )
- logger
- end
- end
-
- # Sets the logger for dependencies and cache store.
- initializer :initialize_framework_logging do
- ActiveSupport::Dependencies.logger ||= Rails.logger
- Rails.cache.logger ||= Rails.logger
- end
-
# Sets the dependency loading mechanism based on the value of
# Configuration#cache_classes.
initializer :initialize_dependency_mechanism do
Oops, something went wrong.

0 comments on commit 7fcf859

Please sign in to comment.