mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactored routes reloading to use RouteSet#append instead keeping block in Engine
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
f1f2fb8ae7
commit
08f4713dba
2 changed files with 9 additions and 23 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue