diff options
Diffstat (limited to 'railties/lib/rails/routes_reloader.rb')
-rw-r--r-- | railties/lib/rails/routes_reloader.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/railties/lib/rails/routes_reloader.rb b/railties/lib/rails/routes_reloader.rb new file mode 100644 index 0000000000..9cfc38630d --- /dev/null +++ b/railties/lib/rails/routes_reloader.rb @@ -0,0 +1,54 @@ +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 + |