Permalink
Browse files

Refactored routes reloading to use RouteSet#append instead keeping bl…

…ock in Engine

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent f1f2fb8 commit 08f4713dba1ae013d5b3c9815cb7e33ea5533be5 @drogus drogus committed with josevalim Oct 6, 2010
Showing with 9 additions and 23 deletions.
  1. +6 −18 railties/lib/rails/application/routes_reloader.rb
  2. +3 −5 railties/lib/rails/engine.rb
View
24 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 @@ def reload!
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
View
8 railties/lib/rails/engine.rb
@@ -419,9 +419,9 @@ def env_config
}
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 @@ def load_seed
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 @@ def load_seed
end
protected
- attr_accessor :routes_draw_block
-
def routes?
defined?(@routes)
end

0 comments on commit 08f4713

Please sign in to comment.