lib/plezi/router/route.rb in plezi-0.14.1 vs lib/plezi/router/route.rb in plezi-0.14.2

- old
+ new

@@ -20,11 +20,11 @@ @prefix_length = @prefix.length + 1 end @controller = controller @param_names = [] @origial = path.dup.freeze - path2regex(m[2]) + prep_params(m[2]) self.class.qp case @controller when Class prep_controller when Regexp @@ -34,21 +34,12 @@ end end def call(request, response) return nil unless match(request.path_info, request) - case @controller - when Class - c = @controller.new - return c._pl_respond(request, response, Thread.current[@route_id]) - when Regexp - params = Thread.current[@route_id] - return nil unless controller =~ params[@param_names[0]] - request.path_info = "/#{params.delete('*'.freeze).to_a.join '/'}" - request.params.update params - end - nil + c = @controller.new + c._pl_respond(request, response, Thread.current[@route_id]) end def fits_params(path, request) params = (Thread.current[@route_id] ||= {}).clear params.update request.params.to_h if request && request.params @@ -68,11 +59,11 @@ def match(req_path, request = nil) # puts "#{req_path} starts with #{@prefix}? #{req_path.start_with?(@prefix)}" req_path.start_with?(@prefix) && fits_params(req_path, request) end - def path2regex(postfix) + def prep_params(postfix) pfa = postfix.split '/'.freeze start = 0; stop = 0 optional = false while pfa.any? name = pfa.shift @@ -104,9 +95,19 @@ @controller.include Plezi::Controller end def self.qp @qp ||= ::Rack::QueryParser.new(Hash, 65_536, 100) + end + end + class RouteRewrite < Route + def call(request, _response) + return nil unless match(request.path_info, request) + params = Thread.current[@route_id] + return nil unless controller =~ params[@param_names[0]] + request.path_info = "/#{params.delete('*'.freeze).to_a.join '/'}" + request.params.update params + nil end end end end