2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# We're patching `ActionDispatch::Routing::Mapper` in
|
|
|
|
# config/initializers/routing_draw.rb
|
|
|
|
module Gitlab
|
|
|
|
module Patch
|
|
|
|
module DrawRoute
|
|
|
|
RoutesNotFound = Class.new(StandardError)
|
|
|
|
|
|
|
|
def draw(routes_name)
|
2020-01-01 13:55:28 +05:30
|
|
|
drawn_any = draw_ee(routes_name) | draw_ce(routes_name)
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
drawn_any || raise(RoutesNotFound, "Cannot find #{routes_name}")
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def draw_ce(routes_name)
|
|
|
|
draw_route(route_path("config/routes/#{routes_name}.rb"))
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw_ee(_)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def route_path(routes_name)
|
|
|
|
Rails.root.join(routes_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw_route(path)
|
|
|
|
if File.exist?(path)
|
|
|
|
instance_eval(File.read(path))
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Gitlab::Patch::DrawRoute.prepend_mod_with('Gitlab::Patch::DrawRoute')
|