diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-12-14 17:54:41 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-12-14 17:54:41 -0600 |
commit | 5f8e48cbd297aca4add4b48efa2136ba6ac851b1 (patch) | |
tree | 939c7670965015dc0721967204d2c533f597ae46 /railties/lib/rails | |
parent | ce970a8bb9f124d19d28270b1ffc8c4532bbbcc1 (diff) | |
download | rails-5f8e48cbd297aca4add4b48efa2136ba6ac851b1.tar.gz rails-5f8e48cbd297aca4add4b48efa2136ba6ac851b1.tar.bz2 rails-5f8e48cbd297aca4add4b48efa2136ba6ac851b1.zip |
Move route reloading into railties
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/application.rb | 49 | ||||
-rw-r--r-- | railties/lib/rails/console_app.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/plugin.rb | 4 |
3 files changed, 48 insertions, 7 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 110311558c..047d252625 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -42,8 +42,13 @@ module Rails end end + attr_reader :route_configuration_files + def initialize Rails.application ||= self + + @route_configuration_files = [] + run_initializers(self) end @@ -65,6 +70,32 @@ module Rails ActionController::Routing::Routes end + def routes_changed_at + routes_changed_at = nil + + route_configuration_files.each do |config| + config_changed_at = File.stat(config).mtime + + if routes_changed_at.nil? || config_changed_at > routes_changed_at + routes_changed_at = config_changed_at + end + end + + routes_changed_at + end + + def reload_routes! + routes.disable_clear_and_finalize = true + + routes.clear! + route_configuration_files.each { |config| load(config) } + routes.finalize! + + nil + ensure + routes.disable_clear_and_finalize = false + end + def initializers initializers = super plugins.each { |p| initializers += p.initializers } @@ -359,6 +390,18 @@ module Rails next unless configuration.frameworks.include?(:action_controller) require 'rails/dispatcher' unless defined?(::Dispatcher) Dispatcher.define_dispatcher_callbacks(configuration.cache_classes) + + unless configuration.cache_classes + # Setup dev mode route reloading + routes_last_modified = routes_changed_at + reload_routes = lambda do + unless routes_changed_at == routes_last_modified + routes_last_modified = routes_changed_at + reload_routes! + end + end + ActionDispatch::Callbacks.before_dispatch { |callbacks| reload_routes } + end end # Routing must be initialized after plugins to allow the former to extend the routes @@ -368,10 +411,8 @@ module Rails # loading module used to lazily load controllers (Configuration#controller_paths). initializer :initialize_routing do next unless configuration.frameworks.include?(:action_controller) - - ActionController::Routing::Routes.controller_paths += configuration.controller_paths - ActionController::Routing::Routes.add_configuration_file(configuration.routes_configuration_file) - ActionController::Routing::Routes.reload! + route_configuration_files << configuration.routes_configuration_file + reload_routes! end # # # Observers are loaded after plugins in case Observers or observed models are modified by plugins. diff --git a/railties/lib/rails/console_app.rb b/railties/lib/rails/console_app.rb index 1ad62e5058..2c4a7a51e8 100644 --- a/railties/lib/rails/console_app.rb +++ b/railties/lib/rails/console_app.rb @@ -27,6 +27,6 @@ end def reload! puts "Reloading..." ActionDispatch::Callbacks.new(lambda {}, true) - ActionController::Routing::Routes.reload + Rails.application.reload_routes! true end diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 86bf032641..8025135a64 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -55,8 +55,8 @@ module Rails initializer :add_routing_file, :after => :initialize_routing do |app| routing_file = "#{path}/config/routes.rb" if File.exist?(routing_file) - app.routes.add_configuration_file(routing_file) - app.routes.reload! + app.route_configuration_files << routing_file + app.reload_routes! end end end |