2018-10-15 09:59:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# We're patching `ActionDispatch::Routing::Mapper` in
|
|
|
|
# config/initializers/routing_draw.rb
|
|
|
|
module Gitlab
|
|
|
|
module Patch
|
|
|
|
module DrawRoute
|
2018-10-17 09:29:39 -04:00
|
|
|
RoutesNotFound = Class.new(StandardError)
|
|
|
|
|
2018-10-15 09:59:00 -04:00
|
|
|
def draw(routes_name)
|
2019-11-19 10:06:24 -05:00
|
|
|
drawn_any = draw_ee(routes_name) | draw_ce(routes_name)
|
2018-10-26 06:42:57 -04:00
|
|
|
|
|
|
|
drawn_any || raise(RoutesNotFound.new("Cannot find #{routes_name}"))
|
2018-10-17 09:29:39 -04:00
|
|
|
end
|
2018-10-15 09:59:00 -04:00
|
|
|
|
2018-10-17 09:29:39 -04:00
|
|
|
def draw_ce(routes_name)
|
2018-10-17 12:55:42 -04:00
|
|
|
draw_route(route_path("config/routes/#{routes_name}.rb"))
|
2018-10-15 09:59:00 -04:00
|
|
|
end
|
|
|
|
|
2018-10-23 08:48:02 -04:00
|
|
|
def draw_ee(_)
|
|
|
|
true
|
2018-10-17 12:55:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def route_path(routes_name)
|
|
|
|
Rails.root.join(routes_name)
|
2018-10-17 09:29:39 -04:00
|
|
|
end
|
2018-10-15 09:59:00 -04:00
|
|
|
|
2018-10-17 09:29:39 -04:00
|
|
|
def draw_route(path)
|
|
|
|
if File.exist?(path)
|
|
|
|
instance_eval(File.read(path))
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
2018-10-15 09:59:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-28 05:09:34 -04:00
|
|
|
|
|
|
|
Gitlab::Patch::DrawRoute.prepend_if_ee('EE::Gitlab::Patch::DrawRoute')
|