2018-10-15 13:59:00 +00: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 13:29:39 +00:00
|
|
|
RoutesNotFound = Class.new(StandardError)
|
|
|
|
|
2018-10-15 13:59:00 +00:00
|
|
|
def draw(routes_name)
|
2019-11-19 15:06:24 +00:00
|
|
|
drawn_any = draw_ee(routes_name) | draw_ce(routes_name)
|
2018-10-26 10:42:57 +00:00
|
|
|
|
|
|
|
drawn_any || raise(RoutesNotFound.new("Cannot find #{routes_name}"))
|
2018-10-17 13:29:39 +00:00
|
|
|
end
|
2018-10-15 13:59:00 +00:00
|
|
|
|
2018-10-17 13:29:39 +00:00
|
|
|
def draw_ce(routes_name)
|
2018-10-17 16:55:42 +00:00
|
|
|
draw_route(route_path("config/routes/#{routes_name}.rb"))
|
2018-10-15 13:59:00 +00:00
|
|
|
end
|
|
|
|
|
2018-10-23 12:48:02 +00:00
|
|
|
def draw_ee(_)
|
|
|
|
true
|
2018-10-17 16:55:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def route_path(routes_name)
|
|
|
|
Rails.root.join(routes_name)
|
2018-10-17 13:29:39 +00:00
|
|
|
end
|
2018-10-15 13:59:00 +00:00
|
|
|
|
2018-10-17 13:29:39 +00:00
|
|
|
def draw_route(path)
|
|
|
|
if File.exist?(path)
|
|
|
|
instance_eval(File.read(path))
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
2018-10-15 13:59:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-28 09:09:34 +00:00
|
|
|
|
|
|
|
Gitlab::Patch::DrawRoute.prepend_if_ee('EE::Gitlab::Patch::DrawRoute')
|