diff options
Diffstat (limited to 'railties/lib/rails/application.rb')
-rw-r--r-- | railties/lib/rails/application.rb | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 85ae8cbbb1..4a7ed2d028 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/hash/reverse_merge' +require 'active_support/file_update_checker' require 'fileutils' require 'rails/plugin' require 'rails/engine' @@ -27,7 +28,7 @@ module Rails # Besides providing the same configuration as Rails::Engine and Rails::Railtie, # the application object has several specific configurations, for example # "allow_concurrency", "cache_classes", "consider_all_requests_local", "filter_parameters", - # "logger", "reload_engines", "reload_plugins" and so forth. + # "logger", "reload_plugins" and so forth. # # Check Rails::Application::Configuration to see them all. # @@ -46,7 +47,6 @@ module Rails autoload :Configuration, 'rails/application/configuration' autoload :Finisher, 'rails/application/finisher' autoload :Railties, 'rails/application/railties' - autoload :RoutesReloader, 'rails/application/routes_reloader' class << self private :new @@ -67,7 +67,7 @@ module Rails raise "You cannot have more than one Rails::Application" if Rails.application super Rails.application = base.instance - Rails.application.add_lib_to_load_paths! + Rails.application.add_lib_to_load_path! ActiveSupport.run_load_hooks(:before_configuration, base.instance) end @@ -84,17 +84,30 @@ module Rails delegate :middleware, :to => :config - def add_lib_to_load_paths! + # This method is called just after an application inherits from Rails::Application, + # allowing the developer to load classes in lib and use them during application + # configuration. + # + # class MyApplication < Rails::Application + # require "my_backend" # in lib/my_backend + # config.i18n.backend = MyBackend + # end + # + # Notice this method takes into consideration the default root path. So if you + # are changing config.root inside your application definition or having a custom + # Rails application, you will need to add lib to $LOAD_PATH on your own in case + # you need to load files in lib/ during the application configuration as well. + def add_lib_to_load_path! #:nodoc: path = config.root.join('lib').to_s $LOAD_PATH.unshift(path) if File.exists?(path) end - def require_environment! + def require_environment! #:nodoc: environment = paths.config.environment.to_a.first require environment if environment end - def eager_load! + def eager_load! #:nodoc: railties.all(&:eager_load!) super end @@ -108,11 +121,18 @@ module Rails end def routes_reloader - @routes_reloader ||= RoutesReloader.new + @routes_reloader ||= ActiveSupport::FileUpdateChecker.new([]){ reload_routes! } end def reload_routes! - routes_reloader.reload! + routes = Rails::Application.routes + routes.disable_clear_and_finalize = true + + routes.clear! + routes_reloader.paths.each { |path| load(path) } + ActiveSupport.on_load(:action_controller) { routes.finalize! } + ensure + routes.disable_clear_and_finalize = false end def initialize! @@ -140,6 +160,7 @@ module Rails config.middleware.build(routes) end end + alias :build_middleware_stack :app def call(env) app.call(env.reverse_merge!(env_defaults)) @@ -196,10 +217,5 @@ module Rails def initialize_generators require "rails/generators" end - - # Application is always reloadable when config.cache_classes is false. - def reloadable?(app) - true - end end end |