From 8fa8a38b906d72905d473d220de06c54883d5a82 Mon Sep 17 00:00:00 2001 From: Billy Ceskavich Date: Tue, 13 Aug 2019 13:51:05 -0400 Subject: [PATCH 1/2] Remove support for Phoenix < v1.4.7 We are moving forward with a requirement of Phoenix >= v1.4.7, since Rolodex now relies on `Phoenix.Router.route_info/4` to collect route docs. --- lib/rolodex/router.ex | 28 ++++------------------------ lib/rolodex/router/route_info.ex | 18 ------------------ mix.exs | 2 +- mix.lock | 7 ++++--- 4 files changed, 9 insertions(+), 46 deletions(-) diff --git a/lib/rolodex/router.ex b/lib/rolodex/router.ex index 990eecb..228c9fa 100644 --- a/lib/rolodex/router.ex +++ b/lib/rolodex/router.ex @@ -165,35 +165,15 @@ defmodule Rolodex.Router do end defp build_route(verb, path, phoenix_router, config) do + http_action_string = verb |> Atom.to_string() |> String.upcase() + phoenix_router - |> build_route_info(verb, path) + |> Phoenix.Router.route_info(http_action_string, path, "") + |> RouteInfo.from_route_info(verb) |> with_doc_annotation() |> Rolodex.Route.new(config) end - # Backwards compatibility logic for fetching Phoenix route info: - # - # 1.4.0 ~ 1.4.7 — Lookup via private router tree - # >= 1.4.7 — Use publicly supported `Phoenix.Router.route_info/4` - defp build_route_info(phoenix_router, verb, path) do - case function_exported?(Phoenix.Router, :route_info, 4) do - true -> - http_action_string = verb |> Atom.to_string() |> String.upcase() - - phoenix_router - |> Phoenix.Router.route_info(http_action_string, path, "") - |> RouteInfo.from_route_info(verb) - - false -> - phoenix_router.__routes__() - |> Enum.find(fn - %{verb: ^verb, path: ^path} -> true - _ -> false - end) - |> RouteInfo.from_router_tree() - end - end - defp with_doc_annotation(%RouteInfo{controller: controller, action: action} = info) do case Utils.fetch_doc_annotation(controller, action) do {:error, :not_found} -> nil diff --git a/lib/rolodex/router/route_info.ex b/lib/rolodex/router/route_info.ex index 85c1764..f6854f2 100644 --- a/lib/rolodex/router/route_info.ex +++ b/lib/rolodex/router/route_info.ex @@ -39,22 +39,4 @@ defmodule Rolodex.Router.RouteInfo do end def from_route_info(_, _), do: nil - - def from_router_tree(%{ - plug: controller, - opts: action, - path: path, - verb: verb, - pipe_through: pipe_through - }) do - %__MODULE__{ - controller: controller, - action: action, - path: path, - verb: verb, - pipe_through: pipe_through - } - end - - def from_router_tree(_), do: nil end diff --git a/mix.exs b/mix.exs index 01cf108..21b1c58 100644 --- a/mix.exs +++ b/mix.exs @@ -33,7 +33,7 @@ defmodule Rolodex.MixProject do # {:dep_from_hexpm, "~> 0.3.0"}, # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, {:jason, "~> 1.1"}, - {:phoenix, ">= 1.4.0"}, + {:phoenix, ">= 1.4.7"}, {:dialyxir, "~> 1.0.0-rc.4", only: [:dev], runtime: false}, {:ex_doc, ">= 0.0.0", only: :dev} ] diff --git a/mix.lock b/mix.lock index e1f4fe0..9440a00 100644 --- a/mix.lock +++ b/mix.lock @@ -10,8 +10,9 @@ "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, "mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"}, "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"}, - "phoenix": {:hex, :phoenix, "1.4.0", "56fe9a809e0e735f3e3b9b31c1b749d4b436e466d8da627b8d82f90eaae714d2", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm"}, - "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.1", "6668d787e602981f24f17a5fbb69cc98f8ab085114ebfac6cc36e10a90c8e93c", [:mix], [], "hexpm"}, - "plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"}, + "phoenix": {:hex, :phoenix, "1.4.9", "746d098e10741c334d88143d3c94cab1756435f94387a63441792e66ec0ee974", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.8.1 or ~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"}, + "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.2", "496c303bdf1b2e98a9d26e89af5bba3ab487ba3a3735f74bf1f4064d2a845a3e", [:mix], [], "hexpm"}, + "plug": {:hex, :plug, "1.8.3", "12d5f9796dc72e8ac9614e94bda5e51c4c028d0d428e9297650d09e15a684478", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm"}, "plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"}, + "telemetry": {:hex, :telemetry, "0.4.0", "8339bee3fa8b91cb84d14c2935f8ecf399ccd87301ad6da6b71c09553834b2ab", [:rebar3], [], "hexpm"}, } From ee057154d2e379cde2aac59097fbbc2f56a37e61 Mon Sep 17 00:00:00 2001 From: Billy Ceskavich Date: Tue, 13 Aug 2019 13:56:00 -0400 Subject: [PATCH 2/2] v0.10.0 --- README.md | 2 +- mix.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a85cfad..3f157d5 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ deps in `mix.exs`: ```elixir def deps do [ - {:rolodex, "~> 0.9.0"} + {:rolodex, "~> 0.10.0"} ] end ``` diff --git a/mix.exs b/mix.exs index 21b1c58..bf7dba6 100644 --- a/mix.exs +++ b/mix.exs @@ -6,7 +6,7 @@ defmodule Rolodex.MixProject do app: :rolodex, name: "Rolodex", description: "Automated docs generation", - version: "0.9.0", + version: "0.10.0", elixir: "~> 1.7", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod,