diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-10-06 15:54:28 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-10-08 18:23:25 +0200 |
commit | 08f4713dba1ae013d5b3c9815cb7e33ea5533be5 (patch) | |
tree | 1f0a7828eb3a986f1f57a99c4711243b3ae83525 /railties | |
parent | f1f2fb8ae733c4602ba2ec2d7ea830a85c64b4d1 (diff) | |
download | rails-08f4713dba1ae013d5b3c9815cb7e33ea5533be5.tar.gz rails-08f4713dba1ae013d5b3c9815cb7e33ea5533be5.tar.bz2 rails-08f4713dba1ae013d5b3c9815cb7e33ea5533be5.zip |
Refactored routes reloading to use RouteSet#append instead keeping block in Engine
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application/routes_reloader.rb | 24 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 8 |
2 files changed, 9 insertions, 23 deletions
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 diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 1aa24b6808..f8caaef213 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -419,9 +419,9 @@ module Rails } end - def routes(&block) + def routes @routes ||= ActionDispatch::Routing::RouteSet.new - self.routes_draw_block = block if block_given? + @routes.append(&Proc.new) if block_given? @routes end @@ -472,8 +472,8 @@ module Rails paths = self.paths["config/routes"].existent if routes? || paths.any? - app.routes_reloader.blocks[routes] = routes_draw_block app.routes_reloader.paths.unshift(*paths) + app.routes_reloader.route_sets << routes end end @@ -523,8 +523,6 @@ module Rails end protected - attr_accessor :routes_draw_block - def routes? defined?(@routes) end |