summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-02-07 14:19:12 -0600
committerDouwe Maan <douwe@selenight.nl>2017-02-07 14:19:12 -0600
commit636e9bdd11bdb60d9711c3d3ba66406b6d8967ae (patch)
treef07b3438bff4a78bcdb4db00392ebd326b6fe6d6 /lib
parent3f1bc3370ba5245742fd0546b33b43ef631aa325 (diff)
downloadgitlab-ce-636e9bdd11bdb60d9711c3d3ba66406b6d8967ae.tar.gz
Support a string source in the route map
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/route_map.rb32
1 files changed, 15 insertions, 17 deletions
diff --git a/lib/gitlab/route_map.rb b/lib/gitlab/route_map.rb
index 89985d90c10..f96c30b3e33 100644
--- a/lib/gitlab/route_map.rb
+++ b/lib/gitlab/route_map.rb
@@ -6,16 +6,16 @@ module Gitlab
begin
entries = YAML.safe_load(data)
rescue
- raise FormatError, 'Route map needs to be valid YAML'
+ raise FormatError, 'Route map is not valid YAML'
end
- raise FormatError, 'Route map needs to be an array' unless entries.is_a?(Array)
+ raise FormatError, 'Route map is not an array' unless entries.is_a?(Array)
@map = entries.map { |entry| parse_entry(entry) }
end
def public_path_for_source_path(path)
- mapping = @map.find { |mapping| path =~ mapping[:source] }
+ mapping = @map.find { |mapping| mapping[:source] === path }
return unless mapping
path.sub(mapping[:source], mapping[:public])
@@ -24,27 +24,25 @@ module Gitlab
private
def parse_entry(entry)
- raise FormatError, 'Route map entry needs to be a hash' unless entry.is_a?(Hash)
- raise FormatError, 'Route map entry requires a source key' unless entry.has_key?('source')
- raise FormatError, 'Route map entry requires a public key' unless entry.has_key?('public')
+ raise FormatError, 'Route map entry is not a hash' unless entry.is_a?(Hash)
+ raise FormatError, 'Route map entry does not have a source key' unless entry.has_key?('source')
+ raise FormatError, 'Route map entry does not have a public key' unless entry.has_key?('public')
- source_regexp = entry['source']
+ source_pattern = entry['source']
public_path = entry['public']
- unless source_regexp.start_with?('/') && source_regexp.end_with?('/')
- raise FormatError, 'Route map entry source needs to start and end in a slash (/)'
- end
-
- source_regexp = source_regexp[1...-1].gsub('\/', '/')
+ if source_pattern.start_with?('/') && source_pattern.end_with?('/')
+ source_pattern = source_pattern[1...-1].gsub('\/', '/')
- begin
- source_regexp = Regexp.new("^#{source_regexp}$")
- rescue RegexpError => e
- raise FormatError, "Route map entry source needs to be a valid regular expression: #{e}"
+ begin
+ source_pattern = Regexp.new("^#{source_pattern}$")
+ rescue RegexpError => e
+ raise FormatError, "Route map entry source is not a valid regular expression: #{e}"
+ end
end
{
- source: source_regexp,
+ source: source_pattern,
public: public_path
}
end