From 3049e645e5037cd923d0bad3c41c105dd9d791f8 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 29 Sep 2010 20:05:34 +0200 Subject: Moved Rails::RoutesReloader to Rails::Application::RoutesReloader --- railties/lib/rails/application/routes_reloader.rb | 55 +++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 railties/lib/rails/application/routes_reloader.rb (limited to 'railties/lib/rails/application/routes_reloader.rb') 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 -- cgit v1.2.3 From 7b0c592e38e4b1d370e04d856d245f825dfa9cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 2 Oct 2010 17:45:26 +0200 Subject: reload_routes! is part of the public API and should not be removed. --- railties/lib/rails/application/routes_reloader.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/application/routes_reloader.rb') diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index 23b72a0ec6..6da903c1ac 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -8,7 +8,7 @@ module Rails def blocks @blocks ||= {} end - private + def reload! clear! load_blocks @@ -18,6 +18,8 @@ module Rails revert end + protected + def clear! routers.each do |routes| routes.disable_clear_and_finalize = true @@ -32,7 +34,7 @@ module Rails end def load_paths - paths.each { |path| load(path) } + paths.each { |path| load(path) } end def finalize! -- cgit v1.2.3 From 08f4713dba1ae013d5b3c9815cb7e33ea5533be5 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 6 Oct 2010 15:54:28 +0200 Subject: Refactored routes reloading to use RouteSet#append instead keeping block in Engine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/lib/rails/application/routes_reloader.rb | 24 ++++++----------------- 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'railties/lib/rails/application/routes_reloader.rb') diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index 6da903c1ac..1d1f5e1b06 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -1,17 +1,15 @@ module Rails class Application class RoutesReloader < ::ActiveSupport::FileUpdateChecker + attr_reader :route_sets + def initialize super([]) { reload! } - end - - def blocks - @blocks ||= {} + @route_sets = [] end def reload! clear! - load_blocks load_paths finalize! ensure @@ -21,37 +19,27 @@ module Rails protected def clear! - routers.each do |routes| + route_sets.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| + route_sets.each do |routes| ActiveSupport.on_load(:action_controller) { routes.finalize! } end end def revert - routers.each do |routes| + route_sets.each do |routes| routes.disable_clear_and_finalize = false end end - - def routers - blocks.keys - end end end end -- cgit v1.2.3