From 5ed79f0e86f8a0402b0581dcd10c599d24bb57f3 Mon Sep 17 00:00:00 2001 From: Tymon Tobolski Date: Fri, 26 Jan 2018 21:25:56 +0100 Subject: [PATCH] Drop aliases #159 --- config/config.exs | 4 ++-- lib/tesla.ex | 33 ++------------------------------- lib/tesla/mock.ex | 4 ++-- test/tesla_test.exs | 4 ++-- 4 files changed, 8 insertions(+), 37 deletions(-) diff --git a/config/config.exs b/config/config.exs index 6d903890..b1c965db 100644 --- a/config/config.exs +++ b/config/config.exs @@ -2,7 +2,7 @@ # and its dependencies with the aid of the Mix.Config module. use Mix.Config -config :tesla, adapter: :httpc +config :tesla, adapter: Tesla.Adapter.Httpc config :logger, :console, level: :debug, @@ -18,5 +18,5 @@ if Mix.env == :test do errlog_type: :error, sasl_error_logger: false - config :tesla, MockClient, adapter: :mock + config :tesla, MockClient, adapter: Tesla.Mock end diff --git a/lib/tesla.ex b/lib/tesla.ex index 8a566c1f..ab9aa37d 100644 --- a/lib/tesla.ex +++ b/lib/tesla.ex @@ -157,7 +157,6 @@ defmodule Tesla.Builder do """ defmacro plug(middleware, opts \\ nil) do opts = Macro.escape(opts) - middleware = Tesla.alias(middleware) quote do: @__middleware__({unquote(middleware), unquote(opts)}) end @@ -194,7 +193,6 @@ defmodule Tesla.Builder do end defmacro adapter(adapter, opts \\ nil) do - adapter = Tesla.alias(adapter) quote do: @__adapter__({unquote(adapter), unquote(opts)}) end @@ -395,33 +393,6 @@ defmodule Tesla do end end - @aliases [ - httpc: Tesla.Adapter.Httpc, - hackney: Tesla.Adapter.Hackney, - ibrowse: Tesla.Adapter.Ibrowse, - mock: Tesla.Mock, - base_url: Tesla.Middleware.BaseUrl, - headers: Tesla.Middleware.Headers, - query: Tesla.Middleware.Query, - opts: Tesla.Middleware.Opts, - follow_redirects: Tesla.Middleware.FollowRedirects, - method_override: Tesla.Middleware.MethodOverride, - logger: Tesla.Middleware.Logger, - debug_logger: Tesla.Middleware.DebugLogger, - form_urlencoded: Tesla.Middleware.FormUrlencoded, - json: Tesla.Middleware.JSON, - compression: Tesla.Middleware.Compression, - decode_rels: Tesla.Middleware.DecodeRels, - basic_auth: Tesla.Middleware.BasicAuth, - digest_auth: Tesla.Middleware.DigestAuth, - timeout: Tesla.Middleware.Timeout, - retry: Tesla.Middleware.Retry, - fuse: Tesla.Middleware.Fuse, - tuples: Tesla.Middleware.Tuples - ] - def alias(key) when is_atom(key), do: Keyword.get(@aliases, key, key) - def alias(key), do: key - def perform_request(module, client \\ nil, options) do %{fun: fun, pre: pre, post: post} = client || %Tesla.Client{} @@ -473,11 +444,11 @@ defmodule Tesla do end defp module_adapter_from_config(module) do - Application.get_env(:tesla, module, [])[:adapter] |> Tesla.alias() + Application.get_env(:tesla, module, [])[:adapter] end def default_adapter do - Application.get_env(:tesla, :adapter, :httpc) |> Tesla.alias() + Application.get_env(:tesla, :adapter, Tesla.Adapter.Httpc) end def run_default_adapter(env, opts \\ []) do diff --git a/lib/tesla/mock.ex b/lib/tesla/mock.ex index e131a397..9d8c602d 100644 --- a/lib/tesla/mock.ex +++ b/lib/tesla/mock.ex @@ -6,10 +6,10 @@ defmodule Tesla.Mock do ``` # config/test.exs - config :tesla, adapter: :mock + config :tesla, adapter: Tesla.Mock # in case MyClient defines specific adapter with `adapter :specific` - config :tesla, MyClient, adapter: :mock + config :tesla, MyClient, adapter: Tesla.Mock ``` ### Example test diff --git a/test/tesla_test.exs b/test/tesla_test.exs index fa5c73ed..af91841a 100644 --- a/test/tesla_test.exs +++ b/test/tesla_test.exs @@ -121,12 +121,12 @@ defmodule TeslaTest do end test "use adapter override from config" do - Application.put_env(:tesla, EmptyClient, adapter: :mock) + Application.put_env(:tesla, EmptyClient, adapter: Tesla.Mock) assert EmptyClient.__adapter__() == Tesla.Mock end test "prefer config over module setting" do - Application.put_env(:tesla, ModuleAdapterClient, adapter: :mock) + Application.put_env(:tesla, ModuleAdapterClient, adapter: Tesla.Mock) assert ModuleAdapterClient.__adapter__() == Tesla.Mock end end