Refactor routing constraints
What does this MR do?
Refactors routing constraints
Why was this MR needed?
This refactoring make it possible to introduce nesting namespaces and project constrainer in future.
What are the relevant issue numbers?
Extracted from https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7121/