Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplify filters to simply use prepare

  • Loading branch information...
commit c3d58cda24745ec614f6c1d395728a3db4b9175f 1 parent 518cb43
@josevalim josevalim authored
View
6 lib/dynamo/filters/head.ex
@@ -4,11 +4,11 @@ defmodule Dynamo.Filters.Head do
`conn.method` will report to be "GET" and
`conn.original_method` will return "HEAD".
"""
- def service(conn, fun) do
+ def prepare(conn) do
if conn.method == "HEAD" do
- fun.(conn.method("GET"))
+ conn.method("GET")
else
- fun.(conn)
+ conn
end
end
end
View
12 lib/dynamo/filters/methodoverride.ex
@@ -2,17 +2,17 @@ defmodule Dynamo.Filters.MethodOverride do
@moduledoc """
A filter to overwrite "POST" method with the one defined in _method parameter.
"""
- def service(conn, fun) do
+ def prepare(conn) do
if conn.method == "POST" do
conn = conn.fetch(:params)
case Dict.get(conn.params, :_method) do
- "DELETE" -> fun.(conn.method("DELETE"))
- "PUT" -> fun.(conn.method("PUT"))
- "PATCH" -> fun.(conn.method("PATCH"))
- _ -> fun.(conn)
+ "DELETE" -> conn.method("DELETE")
+ "PUT" -> conn.method("PUT")
+ "PATCH" -> conn.method("PATCH")
+ _ -> conn
end
else
- fun.(conn)
+ conn
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.