2011-12-12 16:51:33 -05:00
|
|
|
require "active_support/core_ext/module/delegation"
|
|
|
|
|
2010-09-29 14:05:34 -04:00
|
|
|
module Rails
|
|
|
|
class Application
|
2011-12-12 08:39:22 -05:00
|
|
|
class RoutesReloader
|
2012-06-29 11:39:50 -04:00
|
|
|
attr_reader :route_sets, :paths
|
2012-10-14 06:03:39 -04:00
|
|
|
delegate :execute_if_updated, :execute, :updated?, to: :updater
|
2011-12-12 16:51:33 -05:00
|
|
|
|
2011-12-13 05:23:21 -05:00
|
|
|
def initialize
|
2012-06-29 11:39:50 -04:00
|
|
|
@paths = []
|
|
|
|
@route_sets = []
|
2010-09-29 14:05:34 -04:00
|
|
|
end
|
2010-10-02 11:45:26 -04:00
|
|
|
|
2010-09-29 14:05:34 -04:00
|
|
|
def reload!
|
|
|
|
clear!
|
|
|
|
load_paths
|
|
|
|
finalize!
|
|
|
|
ensure
|
|
|
|
revert
|
|
|
|
end
|
|
|
|
|
2011-12-13 05:23:21 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def updater
|
|
|
|
@updater ||= begin
|
2012-06-29 11:39:50 -04:00
|
|
|
updater = ActiveSupport::FileUpdateChecker.new(paths) { reload! }
|
2011-12-13 05:23:21 -05:00
|
|
|
updater.execute
|
|
|
|
updater
|
|
|
|
end
|
|
|
|
end
|
2010-10-02 11:45:26 -04:00
|
|
|
|
2010-09-29 14:05:34 -04:00
|
|
|
def clear!
|
2010-10-06 09:54:28 -04:00
|
|
|
route_sets.each do |routes|
|
2010-09-29 14:05:34 -04:00
|
|
|
routes.disable_clear_and_finalize = true
|
|
|
|
routes.clear!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_paths
|
2010-10-02 11:45:26 -04:00
|
|
|
paths.each { |path| load(path) }
|
2010-09-29 14:05:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
2010-10-06 09:54:28 -04:00
|
|
|
route_sets.each do |routes|
|
2012-01-06 11:04:34 -05:00
|
|
|
routes.finalize!
|
2010-09-29 14:05:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def revert
|
2010-10-06 09:54:28 -04:00
|
|
|
route_sets.each do |routes|
|
2010-09-29 14:05:34 -04:00
|
|
|
routes.disable_clear_and_finalize = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|