1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/lib/rails/application/routes_reloader.rb
José Valim 226d8e745a Refactor MetalLoader and RoutesReloader to rely less on class configuration.
Signed-off-by: Carl Lerche <carllerche@mac.com>
2010-01-28 10:28:40 -08:00

46 lines
No EOL
989 B
Ruby

module Rails
class Application
class RoutesReloader
attr_reader :paths
def initialize
@paths, @last_change_at = [], nil
end
def changed_at
routes_changed_at = nil
paths.each do |path|
config_changed_at = File.stat(path).mtime
if routes_changed_at.nil? || config_changed_at > routes_changed_at
routes_changed_at = config_changed_at
end
end
routes_changed_at
end
def reload!
routes = Rails::Application.routes
routes.disable_clear_and_finalize = true
routes.clear!
paths.each { |path| load(path) }
routes.finalize!
nil
ensure
routes.disable_clear_and_finalize = false
end
def reload_if_changed
current_change_at = changed_at
if @last_change_at != current_change_at
@last_change_at = current_change_at
reload!
end
end
end
end
end