Skip to content

Commit 3020bc5

Browse files
committedFeb 13, 2015
update deps. add matched controller/action
1 parent 1d7a571 commit 3020bc5

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed
 

‎lib/http_router.ex

+16-8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ defmodule HttpRouter do
8484
@http_methods [ :get, :post, :put, :patch, :delete, :any ]
8585

8686
@default_options [
87+
add_match_details_to_private: true,
8788
allow_copy_req_content_type: true,
8889
allow_head: true,
8990
allow_method_override: true,
@@ -176,7 +177,7 @@ defmodule HttpRouter do
176177
# its face when accessing an undefined route.
177178
def do_match(_,_) do
178179
fn conn ->
179-
conn |> send_resp(404, "")
180+
conn |> Plug.Conn.send_resp(404, "")
180181
end
181182
end
182183

@@ -300,6 +301,7 @@ defmodule HttpRouter do
300301

301302
## Private API
302303

304+
defp ignore_args(nil), do: ""
303305
defp ignore_args(str) do
304306
str
305307
|> String.to_char_list
@@ -353,9 +355,9 @@ defmodule HttpRouter do
353355
do_build_match :options, route, body, caller
354356
end
355357
defp build_match(method, route, handler, action, caller) do
356-
body = build_body handler, action
357-
# body_json = build_body handler, action, :json
358-
# body_xml = build_body handler, action, :xml
358+
body = build_body handler, action, caller
359+
# body_json = build_body handler, action, caller, :json
360+
# body_xml = build_body handler, action, caller, :xml
359361

360362
[ #do_build_match(method, route <> ".json", body_json, caller),
361363
#do_build_match(method, route <> ".xml", body_xml, caller),
@@ -375,8 +377,8 @@ defmodule HttpRouter do
375377
end
376378
end
377379

378-
defp build_body(handler, action), do: build_body(handler, action, :skip)
379-
defp build_body(handler, action, add_header) do
380+
defp build_body(handler, action, caller), do: build_body(handler, action, caller, :skip)
381+
defp build_body(handler, action, _caller, add_header) do
380382
header = case add_header do
381383
:json -> [{"accept", "application/json"}]
382384
:xml -> [{"accept", "application/xml"}]
@@ -385,8 +387,14 @@ defmodule HttpRouter do
385387

386388
quote do
387389
opts = [ action: unquote(action), args: binding() ]
388-
unquote(handler).call %{ conn | req_headers: unquote(header) ++
389-
conn.req_headers }, unquote(handler).init(opts)
390+
private = conn.private
391+
|> Map.put(:controller, unquote(handler))
392+
|> Map.put(:handler, unquote(handler))
393+
|> Map.put(:action, unquote(action))
394+
395+
%{ conn | req_headers: unquote(header) ++ conn.req_headers,
396+
private: private }
397+
|> unquote(handler).call(unquote(handler).init(opts))
390398
end
391399
end
392400

‎mix.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule HttpRouter.Mixfile do
33

44
def project do
55
[ app: :http_router,
6-
version: "0.0.3",
6+
version: "0.0.4",
77
elixir: "~> 1.0",
88
deps: deps,
99
name: "HttpRouter",
@@ -21,7 +21,7 @@ defmodule HttpRouter.Mixfile do
2121
defp deps do
2222
[ { :cowboy, "~> 1.0.0" },
2323
{ :plug, "~> 0.9.0" },
24-
{ :poison, "~> 1.2.0" },
24+
{ :poison, "~> 1.3.0" },
2525
{ :xml_builder, "~> 0.0.5" },
2626
{ :earmark, "~> 0.1.10", only: :docs },
2727
{ :ex_doc, "~> 0.6.1", only: :docs },

‎mix.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%{"cowboy": {:hex, :cowboy, "1.0.0"},
22
"cowlib": {:hex, :cowlib, "1.0.1"},
33
"dialyze": {:hex, :dialyze, "0.1.3"},
4-
"earmark": {:hex, :earmark, "0.1.12"},
4+
"earmark": {:hex, :earmark, "0.1.13"},
55
"ex_doc": {:hex, :ex_doc, "0.6.2"},
66
"excoveralls": {:hex, :excoveralls, "0.3.8"},
77
"exjsx": {:hex, :exjsx, "3.1.0"},
@@ -10,7 +10,7 @@
1010
"inch_ex": {:hex, :inch_ex, "0.2.4"},
1111
"jsx": {:hex, :jsx, "2.4.0"},
1212
"plug": {:hex, :plug, "0.9.0"},
13-
"poison": {:hex, :poison, "1.2.1"},
13+
"poison": {:hex, :poison, "1.3.1"},
1414
"ranch": {:hex, :ranch, "1.0.0"},
1515
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.1"},
1616
"xml_builder": {:hex, :xml_builder, "0.0.5"}}

0 commit comments

Comments
 (0)
Please sign in to comment.