Permalink
Browse files

Making changes as per the comments

  • Loading branch information...
1 parent 69d9722 commit df63a28801db18b18eb6df8df7f4e3d6380da9b4 @jeregrine committed Feb 23, 2014
Showing with 28 additions and 19 deletions.
  1. +9 −0 lib/phoenix/adapters/cowboy.ex
  2. +4 −19 lib/phoenix/router/router.ex
  3. +15 −0 lib/phoenix/router/websocket_mapper.ex
@@ -0,0 +1,9 @@
+defmodule Phoenix.Adapters.Cowboy do
+ def setup_options(module, options, dispatch_options) do
+ dispatch = Enum.concat [dispatch_options,
+ Dict.get(options, :dispatch, []),
+ [{:_, Plug.Adapters.Cowboy.Handler, { module, [] }}]]
+
+ Dict.put(@options, :dispatch, [{:_, dispatch}])
+ end
+end
@@ -7,12 +7,12 @@ defmodule Phoenix.Router do
defmacro __using__(plug_adapter_options \\ []) do
quote do
use Phoenix.Router.Mapper
+ use Phoenix.Router.WebsocketMapper
+
import unquote(__MODULE__)
@before_compile unquote(__MODULE__)
use Plug.Builder
- Module.register_attribute __MODULE__, :dispatch_options, accumulate: true, persist: false
-
@options unquote(plug_adapter_options)
end
end
@@ -28,11 +28,9 @@ defmodule Phoenix.Router do
end
def start do
- if dispatch = Phoenix.Router.setup_cowboy_dispatch(__MODULE__, @options, @dispatch_options) do
- options = Dict.put(@options, :dispatch, dispatch)
- end
+ options = Phoenix.Adapters.Cowboy.setup_options(__MODULE__, @options, @dispatch_options)
- IO.puts "Running #{__MODULE__} with Cowboy with #{inspect options}"
+ IO.puts "Running #{__MODULE__} with Cowboy on port #{inspect options}"
Plug.Adapters.Cowboy.http __MODULE__, [], options
end
end
@@ -56,19 +54,6 @@ defmodule Phoenix.Router do
end
end
- defmacro websocket(path, handler, options \\ []) do
- quote do
- @dispatch_options {unquote(path), unquote(handler), unquote(options) }
- end
- end
-
- def setup_cowboy_dispatch(module, options, dispatch_options \\ []) do
- dispatch = Enum.concat [dispatch_options,
- Dict.get(options, :dispatch, []),
- [{:_, Plug.Adapters.Cowboy.Handler, { module, [] }}]]
- [{:_, dispatch}]
- end
-
def dispatch(conn, router, http_method, path) do
request = Dispatcher.Request.new(conn: conn,
router: router,
@@ -0,0 +1,15 @@
+defmodule Phoenix.Router.WebsocketMapper do
+ defmacro __using__(_options) do
+ quote do
+ Module.register_attribute __MODULE__, :dispatch_options, accumulate: true,
+ persist: false
+ import unquote(__MODULE__)
+ end
+ end
+
+ defmacro websocket(path, handler, options \\ []) do
+ quote do
+ @dispatch_options {unquote(path), unquote(handler), unquote(options) }
+ end
+ end
+end

0 comments on commit df63a28

Please sign in to comment.