Make it possible to add EE only route
And if it cannot find any routes, raise an error
This commit is contained in:
parent
1581f75fb5
commit
f1701c0fec
|
@ -334,12 +334,17 @@ full implementation details.
|
|||
|
||||
### Code in `config/routes`
|
||||
|
||||
When we add `draw :admin` in `config/routes.rb`, the application will also
|
||||
load the file located in `config/routes/admin.rb`, and also
|
||||
`ee/config/routes/admin.rb` if the file exists.
|
||||
When we add `draw :admin` in `config/routes.rb`, the application will try to
|
||||
load the file located in `config/routes/admin.rb`, and also try to load the
|
||||
file located in `ee/config/routes/admin.rb`.
|
||||
|
||||
So if we want to extend a particular route file, just add the same file
|
||||
located in `ee/config/routes`.
|
||||
It should at least load one file, at most two files. If it cannot find any
|
||||
files, an error will be raised.
|
||||
|
||||
This means if we want to extend a particular CE route file, just add the same
|
||||
file located in `ee/config/routes`. If we want to add an EE only route, we
|
||||
could still use `draw :ee_only` and add `ee/config/routes/ee_only.rb` without
|
||||
adding `config/routes/ee_only.rb`.
|
||||
|
||||
### Code in `app/controllers/`
|
||||
|
||||
|
|
|
@ -5,16 +5,28 @@
|
|||
module Gitlab
|
||||
module Patch
|
||||
module DrawRoute
|
||||
def draw(routes_name)
|
||||
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
|
||||
RoutesNotFound = Class.new(StandardError)
|
||||
|
||||
draw_ee(routes_name)
|
||||
def draw(routes_name)
|
||||
draw_ce(routes_name) | draw_ee(routes_name) ||
|
||||
raise(RoutesNotFound.new("Cannot find #{routes_name}"))
|
||||
end
|
||||
|
||||
def draw_ce(routes_name)
|
||||
draw_route(Rails.root.join("config/routes/#{routes_name}.rb"))
|
||||
end
|
||||
|
||||
def draw_ee(routes_name)
|
||||
path = Rails.root.join("ee/config/routes/#{routes_name}.rb")
|
||||
draw_route(Rails.root.join("ee/config/routes/#{routes_name}.rb"))
|
||||
end
|
||||
|
||||
instance_eval(File.read(path)) if File.exist?(path)
|
||||
def draw_route(path)
|
||||
if File.exist?(path)
|
||||
instance_eval(File.read(path))
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue