diff options
-rw-r--r-- | railties/lib/rails/application.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/application/routes_reloader.rb | 55 | ||||
-rw-r--r-- | railties/lib/rails/routes_reloader.rb | 54 |
3 files changed, 57 insertions, 56 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 8170be2f65..aafbbc29ee 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -1,7 +1,6 @@ require 'active_support/core_ext/hash/reverse_merge' require 'active_support/file_update_checker' require 'fileutils' -require 'rails/routes_reloader' require 'rails/plugin' require 'rails/engine' @@ -40,6 +39,7 @@ 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 def inherited(base) @@ -82,7 +82,7 @@ module Rails end def routes_reloader - @routes_reloader ||= Rails::RoutesReloader.new + @routes_reloader ||= RoutesReloader.new end def initialize! diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb new file mode 100644 index 0000000000..23b72a0ec6 --- /dev/null +++ b/railties/lib/rails/application/routes_reloader.rb @@ -0,0 +1,55 @@ +module Rails + class Application + class RoutesReloader < ::ActiveSupport::FileUpdateChecker + def initialize + super([]) { reload! } + end + + def blocks + @blocks ||= {} + end + private + def reload! + clear! + load_blocks + load_paths + finalize! + ensure + revert + end + + def clear! + routers.each do |routes| + routes.disable_clear_and_finalize = true + routes.clear! + end + end + + def load_blocks + blocks.each do |routes, block| + routes.draw(&block) if block + end + end + + def load_paths + paths.each { |path| load(path) } + end + + def finalize! + routers.each do |routes| + ActiveSupport.on_load(:action_controller) { routes.finalize! } + end + end + + def revert + routers.each do |routes| + routes.disable_clear_and_finalize = false + end + end + + def routers + blocks.keys + end + end + end +end diff --git a/railties/lib/rails/routes_reloader.rb b/railties/lib/rails/routes_reloader.rb deleted file mode 100644 index 9cfc38630d..0000000000 --- a/railties/lib/rails/routes_reloader.rb +++ /dev/null @@ -1,54 +0,0 @@ -module Rails - class RoutesReloader < ::ActiveSupport::FileUpdateChecker - def initialize - super([]) { reload! } - end - - def blocks - @blocks ||= {} - end - private - def reload! - clear! - load_blocks - load_paths - finalize! - ensure - revert - end - - def clear! - routers.each do |routes| - routes.disable_clear_and_finalize = true - routes.clear! - end - end - - def load_blocks - blocks.each do |routes, block| - routes.draw(&block) if block - end - end - - def load_paths - paths.each { |path| load(path) } - end - - def finalize! - routers.each do |routes| - ActiveSupport.on_load(:action_controller) { routes.finalize! } - end - end - - def revert - routers.each do |routes| - routes.disable_clear_and_finalize = false - end - end - - def routers - blocks.keys - end - end -end - |