Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 62 lines (51 sloc) 1.275 kB
fa1d9a8 @josevalim Speed up development by only reloading classes if dependencies files …
josevalim authored
1 require "active_support/core_ext/module/delegation"
2
3049e64 @drogus Moved Rails::RoutesReloader to Rails::Application::RoutesReloader
drogus authored
3 module Rails
4 class Application
5c234ab @josevalim Composition > inheritance.
josevalim authored
5 class RoutesReloader
363a06f @wycats Routes reloader knows how to reload external files
wycats authored
6 attr_reader :route_sets, :paths, :external_routes
80256ab @josevalim FileUpdateChecker should be able to handle deleted files.
josevalim authored
7 delegate :execute_if_updated, :execute, :updated?, :to => :updater
fa1d9a8 @josevalim Speed up development by only reloading classes if dependencies files …
josevalim authored
8
80256ab @josevalim FileUpdateChecker should be able to handle deleted files.
josevalim authored
9 def initialize
363a06f @wycats Routes reloader knows how to reload external files
wycats authored
10 @paths = []
11 @route_sets = []
12 @external_routes = []
3049e64 @drogus Moved Rails::RoutesReloader to Rails::Application::RoutesReloader
drogus authored
13 end
7b0c592 @josevalim reload_routes! is part of the public API and should not be removed.
josevalim authored
14
3049e64 @drogus Moved Rails::RoutesReloader to Rails::Application::RoutesReloader
drogus authored
15 def reload!
16 clear!
17 load_paths
18 finalize!
19 ensure
20 revert
21 end
22
80256ab @josevalim FileUpdateChecker should be able to handle deleted files.
josevalim authored
23 private
24
25 def updater
26 @updater ||= begin
72a2edd @carlosantoniodasilva Refactor RoutesReloader a bit to avoid creating extra hash objects
carlosantoniodasilva authored
27 dirs = @external_routes.each_with_object({}) do |dir, hash|
28 hash[dir.to_s] = %w(rb)
363a06f @wycats Routes reloader knows how to reload external files
wycats authored
29 end
30
31 updater = ActiveSupport::FileUpdateChecker.new(paths, dirs) { reload! }
80256ab @josevalim FileUpdateChecker should be able to handle deleted files.
josevalim authored
32 updater.execute
33 updater
34 end
35 end
7b0c592 @josevalim reload_routes! is part of the public API and should not be removed.
josevalim authored
36
3049e64 @drogus Moved Rails::RoutesReloader to Rails::Application::RoutesReloader
drogus authored
37 def clear!
08f4713 @drogus Refactored routes reloading to use RouteSet#append instead keeping bl…
drogus authored
38 route_sets.each do |routes|
3049e64 @drogus Moved Rails::RoutesReloader to Rails::Application::RoutesReloader
drogus authored
39 routes.disable_clear_and_finalize = true
40 routes.clear!
41 end
42 end
43
44 def load_paths
7b0c592 @josevalim reload_routes! is part of the public API and should not be removed.
josevalim authored
45 paths.each { |path| load(path) }
3049e64 @drogus Moved Rails::RoutesReloader to Rails::Application::RoutesReloader
drogus authored
46 end
47
48 def finalize!
08f4713 @drogus Refactored routes reloading to use RouteSet#append instead keeping bl…
drogus authored
49 route_sets.each do |routes|
0db9394 @josevalim We should finalize the routes as soon as possible and not wait for th…
josevalim authored
50 routes.finalize!
3049e64 @drogus Moved Rails::RoutesReloader to Rails::Application::RoutesReloader
drogus authored
51 end
52 end
53
54 def revert
08f4713 @drogus Refactored routes reloading to use RouteSet#append instead keeping bl…
drogus authored
55 route_sets.each do |routes|
3049e64 @drogus Moved Rails::RoutesReloader to Rails::Application::RoutesReloader
drogus authored
56 routes.disable_clear_and_finalize = false
57 end
58 end
59 end
60 end
61 end
Something went wrong with that request. Please try again.