diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-10-26 12:57:43 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-10-26 12:57:43 +0000 |
commit | 359474a29ee925faf51322707f9c11272542cfd7 (patch) | |
tree | 35df4ab6112cd7d223863aa08437d91232906257 /lib | |
parent | dbe15b4add90f6ddd38e1c8a299c05a55ebb75ff (diff) | |
parent | 84e441d808744fe084a81939e187e98ead23d7a8 (diff) | |
download | gitlab-ce-359474a29ee925faf51322707f9c11272542cfd7.tar.gz |
Merge branch '7864-ee-routes' into 'master'
CE: Put EE routes in EE files under EE directories
See merge request gitlab-org/gitlab-ce!22376
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/patch/draw_route.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/gitlab/patch/draw_route.rb b/lib/gitlab/patch/draw_route.rb new file mode 100644 index 00000000000..b00244a6e04 --- /dev/null +++ b/lib/gitlab/patch/draw_route.rb @@ -0,0 +1,38 @@ +# 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) + drawn_any = draw_ce(routes_name) | draw_ee(routes_name) + + drawn_any || raise(RoutesNotFound.new("Cannot find #{routes_name}")) + 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 |