summaryrefslogtreecommitdiff
path: root/lib/constraints/namespace_url_constrainer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/constraints/namespace_url_constrainer.rb')
-rw-r--r--lib/constraints/namespace_url_constrainer.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/constraints/namespace_url_constrainer.rb b/lib/constraints/namespace_url_constrainer.rb
new file mode 100644
index 00000000000..23920193743
--- /dev/null
+++ b/lib/constraints/namespace_url_constrainer.rb
@@ -0,0 +1,13 @@
+class NamespaceUrlConstrainer
+ def matches?(request)
+ id = request.path.sub(/\A\/+/, '').split('/').first.sub(/.atom\z/, '')
+
+ if id =~ Gitlab::Regex.namespace_regex
+ find_resource(id)
+ end
+ end
+
+ def find_resource(id)
+ Namespace.find_by_path(id)
+ end
+end