lib/tomogram_routing/tomogram.rb in tomogram_routing-0.1.3 vs lib/tomogram_routing/tomogram.rb in tomogram_routing-0.1.4
- old
+ new
@@ -7,34 +7,43 @@
res.push(Request.new.merge(doc))
end)
end
def find_request(method:, path:)
+ path = find_request_path(method: method, path: path)
find do |doc|
- path = find_request_path(method: method, path: path)
doc['path'] == path && doc['method'] == method
end
end
private
def find_request_path(method:, path:)
return '' unless path && path.size > 0
- path = remove_the_slash_at_the_end2(path)
+ path = normalize_path(path)
action = search_for_an_exact_match(method, path, self)
return action['path'] if action
action = search_with_parameter(method, path, self)
return action['path'] if action && action.first
''
end
+ def normalize_path(path)
+ path = cut_off_query_params(path)
+ remove_the_slash_at_the_end2(path)
+ end
+
def remove_the_slash_at_the_end2(path)
return path[0..-2] if path[-1] == '/'
path
+ end
+
+ def cut_off_query_params(path)
+ path.gsub(/\?.*\z/, '')
end
def search_for_an_exact_match(method, path, documentation)
documentation.find do |action|
action['path'] == path && action['method'] == method