Skip to content

Commit 3aab4db

Browse files
committed
Improve pattern matching
1 parent 42bcf79 commit 3aab4db

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

lib/bypass/instance.ex

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -308,30 +308,26 @@ defmodule Bypass.Instance do
308308
{route, Map.get(expectations, route)}
309309
end
310310

311-
defp match_route(path, route) do
312-
case length(path) == length(route) do
313-
true ->
314-
path
315-
|> Enum.zip(route)
316-
|> Enum.reduce_while(
317-
{true, %{}},
318-
fn
319-
{value, {param, _, _}}, {_, params} ->
320-
{:cont, {true, Map.put(params, Atom.to_string(param), value)}}
321-
322-
{segment, segment}, acc ->
323-
{:cont, acc}
324-
325-
_, _ ->
326-
{:halt, {false, nil}}
327-
end
328-
)
329-
330-
false ->
331-
{false, nil}
332-
end
311+
defp match_route(path, route) when length(path) == length(route) do
312+
path
313+
|> Enum.zip(route)
314+
|> Enum.reduce_while(
315+
{true, %{}},
316+
fn
317+
{value, {param, _, _}}, {_, params} ->
318+
{:cont, {true, Map.put(params, Atom.to_string(param), value)}}
319+
320+
{segment, segment}, acc ->
321+
{:cont, acc}
322+
323+
_, _ ->
324+
{:halt, {false, nil}}
325+
end
326+
)
333327
end
334328

329+
defp match_route(_, _), do: {false, nil}
330+
335331
defp do_up(port, ref) do
336332
plug_opts = [self()]
337333
{:ok, socket} = :ranch_tcp.listen(so_reuseport() ++ [ip: listen_ip(), port: port])

0 commit comments

Comments
 (0)